Menu
Amazon DynamoDB
Developer Guide (API Version 2012-08-10)

Using the CLI

You can use the AWS Command Line Interface (AWS CLI) to control multiple AWS services from the command line and automate them through scripts. You can use the AWS CLI for ad hoc operations, such as creating a table. You can also use it to embed DynamoDB operations within utility scripts.

Before you can set up the AWS CLI on your computer, make sure to first get your AWS Access Key ID and Secret Key. For more information see Get Your AWS Access Key ID and Secret Key.

For a complete listing of all the commands available to you in the DynamoDB AWS CLI, go to http://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html.

Downloading and Configuring the AWS CLI

The AWS CLI is available at http://aws.amazon.com/cli, and will run on Windows, Mac, or Linux. After you download the AWS CLI, to install and configure it:

  1. Go to the AWS Command Line Interface User Guide.

  2. Follow the instructions for Installing the AWS CLI and Configuring the AWS CLI.

Using the AWS CLI with DynamoDB

The command line format consists of a DynamoDB operation name, followed by the parameters for that operation. The AWS CLI supports a shorthand syntax for the parameter values, as well as JSON.

For example, the following command will create a table named Music. The partition key is Artist, and the sort key is SongTitle. (For easier readability, long commands in this section are broken into separate lines.)

Copy
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=1,WriteCapacityUnits=1

The following commands will add new items to the table. These example use a combination of shorthand syntax and JSON.

Copy
aws dynamodb put-item \ --table-name Music \ --item \ '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}}' \ --return-consumed-capacity TOTAL aws dynamodb put-item \ --table-name Music \ --item \ '{"Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}, "AlbumTitle": {"S": "Songs About Life"}}' \ --return-consumed-capacity TOTAL aws dynamodb put-item \ --table-name Music \ --item '{ \ "Artist": {"S": "Acme Band"}, \ "SongTitle": {"S": "Happy Day"}, \ "AlbumTitle": {"S": "Songs About Life"} }' \ --return-consumed-capacity TOTAL

On the command line, it can be difficult to compose valid JSON; however, the AWS CLI can read JSON files. For example, consider the following JSON snippet which is stored in a file named key-conditions.json:

Copy
{ "Artist": { "AttributeValueList": [ { "S": "No One You Know" } ], "ComparisonOperator": "EQ" }, "SongTitle": { "AttributeValueList": [ { "S": "Call Me Today" } ], "ComparisonOperator": "EQ" } }

You can now issue a Query request using the AWS CLI. In this example, the contents of the key-conditions.json file are used for the --key-conditions parameter:

Copy
aws dynamodb query --table-name Music --key-conditions file://key-conditions.json

For more documentation on using the AWS CLI with DynamoDB, go to http://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html.

Using the AWS CLI with Downloadable DynamoDB

The AWS CLI can interact with DynamoDB running on your computer. To enable this, add the --endpoint-url parameter to each command:

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

Here is an example, using the AWS CLI to list the tables in a local database:

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

If DynamoDB is using a port number other than the default (8000), you will need to modify the --endpoint-url value accordingly.

Note

The AWS CLI cannot use the downloadable version of DynamoDB as a default endpoint; therefore, you need to specify --endpoint-url with each command.