AWS DynamoDB Table Creation: CLI Command and Best Practices

DynamoDB Table Creation CLI Command

Prev Question Next Question

Question

You have to create a DynamoDB table called Customers which will have two attributes.

One is the ID which will be the partition key, and the other is the Name which will be the sort key.

Which of the following is the right definition for the CLI command that would be used to create the table?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - A.

An example of this is given in the AWS Documentation.

Option B is incorrect since the keys are not being defined here.

Option C is incorrect since the Name key should be RANGE and the ID should be HASH.

Option D is incorrect since the right CLI command is create-table.

For more information on working with tables, please refer to the below URL-

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.Basics.html
Example

The following AWS CLI example shows how to create a table (Music). The primary key consists of Artist (partition key) and

SongTitle (sort key), each of which has a data type of String. The maximum throughput for this table is 10 read capacity units and

5 write capacity units.

aws dynamodb create-table \

--table-name Music \

--attribute-definitions \
AttributeName=Artist,AttributeType=S \
AttributeName=SongTitle,AttributeType-S \

--key-schema \
AttributeName=Artist,KeyType=HASH \
AttributeName=SongTitle,KeyType=RANGE \

--provisioned-throughput \
ReadCapacityUnits=10,WriteCapacityUnits=5

ag

The correct CLI command to create the DynamoDB table with the specified attributes is:

sql
aws dynamodb create-table \ --table-name Customers \ --attribute-definitions \ AttributeName=ID,AttributeType=N \ AttributeName=Name,AttributeType=S \ --key-schema \ AttributeName=ID,KeyType=HASH \ AttributeName=Name,KeyType=RANGE \ --provisioned-throughput \ ReadCapacityUnits=10,WriteCapacityUnits=5

Explanation:

The aws dynamodb create-table command is used to create a new DynamoDB table. The command takes several parameters, which are explained below:

--table-name : This specifies the name of the table to be created. In this case, the table name is "Customers".

--attribute-definitions : This parameter defines the attributes of the table. In this case, the table has two attributes: "ID" and "Name". The ID attribute is of type "N" (number), and the Name attribute is of type "S" (string).

--key-schema : This parameter specifies the primary key schema of the table. The primary key consists of two attributes: the partition key and the sort key. In this case, the partition key is "ID", and the sort key is "Name". The partition key is designated as the hash key using the KeyType=HASH parameter, and the sort key is designated as the range key using the KeyType=RANGE parameter.

--provisioned-throughput : This parameter specifies the initial provisioned throughput capacity for the table. The provisioned throughput consists of two values: the read capacity units (RCUs) and the write capacity units (WCUs). In this case, the table is provisioned with 10 RCUs and 5 WCUs.

Therefore, option C is the correct answer. Option A is incorrect because it specifies the key schema in reverse order, with the Name attribute designated as the partition key and the ID attribute designated as the sort key. Option B is incorrect because it does not specify the key schema. Option D is incorrect because it uses the set-table command, which is not used to create a new table.