Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
DynamoDB Cookbook

You're reading from   DynamoDB Cookbook Over 90 hands-on recipes to design Internet scalable web and mobile applications with Amazon DynamoDB

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781784393755
Length 266 pages
Edition 1st Edition
Concepts
Arrow right icon
Author (1):
Arrow left icon
Tanmay Deshpande Tanmay Deshpande
Author Profile Icon Tanmay Deshpande
Tanmay Deshpande
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Taking Your First Steps with DynamoDB FREE CHAPTER 2. Operating with DynamoDB Tables 3. Manipulating DynamoDB Items 4. Managing DynamoDB Indexes 5. Exploring Higher Level Programming Interfaces for DynamoDB 6. Securing DynamoDB 7. DynamoDB Best Practices 8. Integrating DynamoDB with other AWS Services 9. Developing Web Applications using DynamoDB 10. Developing Mobile Applications using DynamoDB 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:

    How to do it…
  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:

    How to do it…

    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.

You have been reading a chapter from
DynamoDB Cookbook
Published in: Sep 2015
Publisher:
ISBN-13: 9781784393755
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image