Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamodb : Create a table in with AttributeType Map, List, JSON with CreateTable

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 
    }

],

... }

like image 248
Periworks Avatar asked Mar 03 '18 10:03

Periworks


People also ask

Can JSON be stored in DynamoDB?

You can store a JSON document as an attribute in a DynamoDB table. To do this, use the withJSON method of Item . This method parses the JSON document and maps each element to a native DynamoDB data type.

Which DynamoDB API is used for creating data in a table?

CreateTable – Creates a new table. Optionally, you can create one or more secondary indexes, and enable DynamoDB Streams for the table. DescribeTable – Returns information about a table, such as its primary key schema, throughput settings, and index information.


1 Answers

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.

like image 196
notionquest Avatar answered Oct 13 '22 10:10

notionquest