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

前端 未结 3 881
囚心锁ツ
囚心锁ツ 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:59

    TL;DR Don't include any non-key attribute definitions in AttributeDefinitions.

    DynamoDB is schemaless (except the key schema)

    That is to say, you do need to specify the key schema (attribute name and type) when you create the table. Well, you don't need to specify any non-key attributes. You can put an item with any attribute later (must include the keys of course).

    From the documentation page, the AttributeDefinitions is defined as:

    An array of attributes that describe the key schema for the table and indexes.

    When you create table, the AttributeDefinitions field is used for the hash and/or range keys only. In your first case, there is hash key only (number 1) while you provide 2 AttributeDefinitions. This is the root cause of the exception.

提交回复
热议问题