7
votes

How can I create in DyanamoDB a table with AttributeType Set, Map or JSON. I don't want to create the table structure by insertion (PutItem) or update of data because I need to create an index that will contains the Map, List or JSON attribute in the projection. I need to do it a creation time (CreateTable). I also prefer to use AWS CLI. Below a sample:

{
TableName : "Music",
KeySchema: [       
    { 
        AttributeName: "Artist", 
        KeyType: "HASH", //Partition key
    }
],
AttributeDefinitions: [
    { 
        AttributeName: "Artist", 
        AttributeType: "S" 
    },
    { 
        AttributeName: "instruments" 
        AttributeType: // Map or List or JSON type 
    }

],

... }

1
AFAIK you cant, the only valid attribute types are S(tring), N(number) and B(inary) docs.aws.amazon.com/amazondynamodb/latest/APIReference/…Purefan

1 Answers

5
votes

While creating the DynamoDB table, you can define only the attributes that are part of the key definitions. In other words, you can define the hash key and sort key attributes only when you create the DynamoDB table. The hash and sort key attribute must be a scalar attribute.

The document and set data types cannot be part of the key attribute. Also, you can't create the index on these attribute types.

Scalar Types – A scalar type can represent exactly one value. The scalar types are number, string, binary, Boolean, and null.

Document Types – A document type can represent a complex structure with nested attributes—such as you would find in a JSON document. The document types are list and map.

Set Types – A set type can represent multiple scalar values. The set types are string set, number set, and binary set.