Skip to content

Instantly share code, notes, and snippets.

@jtsaito
Last active December 2, 2015 08:27
Show Gist options
  • Save jtsaito/4505c4d8b4aee9d9c735 to your computer and use it in GitHub Desktop.
Save jtsaito/4505c4d8b4aee9d9c735 to your computer and use it in GitHub Desktop.
Get DynamoDB item with aws cli

Prerequisites

  1. Created a dynamo db table. We use "travis-ci-deloy-test" with number key "created_at".
  2. Setup aws cli command line tool.
  3. Stored an item with with number key and attribute (in this example, foo: "finger_print").
  4. Set credentials for the table for aws client config (e.g. by setting values in ~/.aws/credentials).

Querying items

First, prepare the query key in a file query_key.json describing the key as json.

{
  "created_at": { "N": "123" }
}
  1. Run the query.
aws dynamodb get-item --table-name travis-ci-deloy-test --key file://query_key.json

This returns the following.

{
    "Item": {
        "created_at": {
            "N": "123"
        },
        "finger_print": {
            "S": "foo"
        }
    }
}

As we can see, aws cli does has returns the raw query result as a json using the (ugly) AttributeValue syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment