Ex:Using the Local Table from CLI

Hands-on Exercise

AWS CLI

To use local table with CLI use the parameter –endpoint-url. The example shown here will create a tables in local DynamoDB.

These commands if used as-in in Windows command shell will give error. To try out these commands on Windows use GitBash shell or replace the terminator character \ with `

aws dynamodb create-table \
    --table-name  test \
    --attribute-definitions \
       AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S  \
    --key-schema \
       AttributeName=PK,KeyType=HASH \
       AttributeName=SK,KeyType=RANGE \
    --provisioned-throughput \
        ReadCapacityUnits=1,WriteCapacityUnits=1 \
    --endpoint-url   http://localhost:8000

This will list the tables available in the local DynamoDB.

aws dynamodb list-tables  --endpoint-url   http://localhost:8000

This will add items to the local dynamo db table

aws dynamodb put-item  \
   --table-name  test \
   --item '{
        "PK": {"S": "doe@example.com"},
        "SK": {"S": "John Doe"},
        "Age": {"N": "31"}
   }'   \
   --endpoint-url   http://localhost:8000
aws dynamodb put-item  \
   --table-name  test \
   --item '{
        "PK": {"S": "doe@example.com"},
        "SK": {"S": "Jane Doe"},
        "Age": {"N": "28"}
   }'   \
   --endpoint-url   http://localhost:8000

Read all items from the table like SELECT * FROM test

aws dynamodb scan  \
   --table-name  test \
   --endpoint-url   http://localhost:8000

Get specific item

aws dynamodb get-item  \
   --table-name  test \
   --key '{
        "PK": {"S": "doe@example.com"},
        "SK": {"S": "John Doe"}
   }' \
   --endpoint-url   http://localhost:8000

Delete the table

aws dynamodb delete-table \
   --table-name  test \
   --endpoint-url   http://localhost:8000

Run commands against table on AWS Cloud

To run the commands against the table on AWS cloud, Remove the parameter –endpoint-url from the sample commands.

--endpoint-url   http://localhost:8000