Number of attributes in key schema must match the number of attributes defined in attribute definitions

前端 未结 3 821
囚心锁ツ
囚心锁ツ 2021-01-30 19:03

I’m trying to create a simple table using DynamoDB JavaScript shell and I’m getting this exception:

{
  "message&quo         


        
3条回答
  •  后悔当初
    2021-01-30 19:51

    I also had this problem and I'll post here what went wrong for me in case it helps someone else.

    In my CreateTableRequest, I had an empty array for the GlobalSecondaryIndexes.

    CreateTableRequest createTableRequest = new CreateTableRequest
    {
      TableName = TableName,
      ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 2, WriteCapacityUnits = 2 },
      KeySchema = new List
      {
         new KeySchemaElement
         {
            AttributeName = "Field1",
            KeyType = KeyType.HASH
         },
         new KeySchemaElement
         {
            AttributeName = "Field2",
            KeyType = KeyType.RANGE
         }
      },
      AttributeDefinitions = new List()
      {
         new AttributeDefinition
         {
             AttributeName = "Field1", 
             AttributeType = ScalarAttributeType.S
         },
         new AttributeDefinition
         {
            AttributeName = "Field2",
            AttributeType = ScalarAttributeType.S
         }
      },
      //GlobalSecondaryIndexes = new List
      //{                            
      //}
    };
    

    Commenting out these lines in the table creation solved my problem. So I guess the list has to be null, not empty.

提交回复
热议问题