Book Image

DynamoDB Cookbook

By : Tanmay Deshpande
Book Image

DynamoDB Cookbook

By: Tanmay Deshpande

Overview of this book

Table of Contents (18 chapters)
DynamoDB Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Setting up AWS Command Line Interface for DynamoDB


The AWS Command Line Interface allows us to operate various AWS resources from the command line itself. In this recipe, we are going to see how to use these and perform operations.

Getting ready

You can download the installer for Windows, Mac, or Linux from http://aws.amazon.com/cli/.

How to do it…

The AWS CLI for DynamoDB supports various commands, such as batch-get-item, batch-write-item, create-table, delete-item, delete-table, describe-table, get-item, list-tables, put-item, query, scan, update-item, update-table, wait, and so on.

To get started, we need to first configure the AWS CLI:

  1. Start Command Prompt, and type the following command:

    aws configure
    
  2. This will ask you for the Access Key, Secret Key, and Region details. If you have not downloaded the AWS keys yet, you can download them from https://console.aws.amazon.com/iam/home?#security_credential.

  3. Here, you can download the Access Keys and save it in a secure place. Once the keys are submitted, you can start accessing DynamoDB from the command line.

  4. We need to list the tables that we have already created, and then we can execute this command:

    aws dynamodb list-tables
    

    The output of the following command is shown below:

  5. We can also run the Query operations from the command line as well. Suppose that we want to Query a product table for id =5, then we have to write this condition in the JSON document and save it on our machine. The JSON file would like this:

    {"id": {"AttributeValueList": [{"S":"5"}],"ComparisonOperator": "EQ" }}

    Assume that we saved it in a file named conditions.json; then, to execute the query, we have to run the following command:

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

    The output would be something like this:

    We can also specify conditions for the Range Key in order to narrow down our results, which is similar to what we did for the Hash Key.

How it works…

The AWS CLI, which is internally called DynamoDB APIs, is used to retrieve results. For authentication, it uses the Access Key and Secret Key that you provide at the time of configuration.

There's more…

You can also try out various other options from the AWS CLI for DynamoDB, which are available at http://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html#cli-aws-dynamodb.