2017-02-20 65 views
0

創建排序和分區鍵創建表時收到此錯誤:上DynamoDb

"One or more parameter values were invalid: 
Number of attributes in KeySchema does not 
exactly match number of attributes defined in AttributeDefinitions" 

我跟着例子here

我有兩節我的鍵控屬性。我唯一想知道的是我的鍵控屬性類型是字符串,而不是數字。我無法以這種或那種方式找到答案。

我實現

private static void CreateTableMember() 
    { 
     string tableName = "Member"; 

     var response = client.CreateTable(new CreateTableRequest 
     { 
      TableName = tableName, 
      AttributeDefinitions = new List<AttributeDefinition>() 
      { 
       new AttributeDefinition 
       { 
        AttributeName = "MasterCustomerId", 
        AttributeType = "S" 
       }, 

       new AttributeDefinition 
       { 
        AttributeName = "LastName", 
        AttributeType = "S" 
       }, 
       new AttributeDefinition 
       { 
        AttributeName = "DistrictId", 
        AttributeType = "S" 
       }, 

       new AttributeDefinition 
       { 
        AttributeName = "EmailAddress", 
        AttributeType = "S" 
       }, 

       new AttributeDefinition 
       { 
        AttributeName = "FirstName", 
        AttributeType = "S" 
       } 
      }, 



      KeySchema = new List<KeySchemaElement>() 
      { 
       new KeySchemaElement 
       { 
       AttributeName = "MasterCustomerId", 
       KeyType = "HASH" // Partition Key 
       }, 
       new KeySchemaElement 
       { 
       AttributeName = "LastName", 
       KeyType = "RANGE" //Sort key 
       } 
      }, 
        ProvisionedThroughput = new ProvisionedThroughput 
      { 
       ReadCapacityUnits = 10, 
       WriteCapacityUnits = 5 
      } 
     }); 

     WaitTillTableCreated(client, tableName, response); 

    } 

回答

0

創建DynamoDB表時,你並不需要指定非關鍵屬性。 DynamoDB沒有固定的模式。相反,每個數據項可能具有不同數量的屬性(除強制性關鍵屬性外)。

刪除非鍵控屬性修復了問題