在DynamoDb上创建排序和分区键

时间:2017-02-20 22:12:40

标签: c# amazon-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);

    }

1 个答案:

答案 0 :(得分:0)

创建DynamoDB表时,无需指定非键属性。 DynamoDB没有固定架构。相反,每个数据项可能具有不同数量的属性(除了必需的键属性)。

删除非键控属性修复了问题