Skip to content

Commit

Permalink
Merge pull request #1166 from awsdocs/dynamodb-examples
Browse files Browse the repository at this point in the history
dynamo db examples
  • Loading branch information
danielgtaylor committed Feb 20, 2015
2 parents ec5bc0a + 533be7d commit 2956ab5
Show file tree
Hide file tree
Showing 13 changed files with 484 additions and 0 deletions.
54 changes: 54 additions & 0 deletions awscli/examples/dynamodb/batch-get-item.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
**To retrieve multiple items from a table**

This example reads multiple items from the *MusicCollection* table using a batch of three GetItem requests. Only the *AlbumTitle* attribute is returned.

Command::

aws dynamodb batch-get-item --request-items file://request-items.json

The arguments for ``--request-items`` are stored in a JSON file, ``request-items.json``. Here are the contents of that file::

{
"MusicCollection": {
"Keys": [
{
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Call Me Today"}
},
{
"Artist": {"S": "Acme Band"},
"SongTitle": {"S": "Happy Day"}
},
{
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Scared of My Shadow"}
}
],
"ProjectionExpression":"AlbumTitle"
}
}

Output::

{
"UnprocessedKeys": {},
"Responses": {
"MusicCollection": [
{
"AlbumTitle": {
"S": "Somewhat Famous"
}
},
{
"AlbumTitle": {
"S": "Blue Sky Blues"
}
},
{
"AlbumTitle": {
"S": "Louder Than Ever"
}
}
]
}
}
47 changes: 47 additions & 0 deletions awscli/examples/dynamodb/batch-write-item.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
**To add multiple items to a table**

This example adds three new items to the *MusicCollection* table using a batch of three PutItem requests.

Command::

aws dynamodb batch-write-item --request-items file://request-items.json

The arguments for ``--request-items`` are stored in a JSON file, ``request-items.json``. Here are the contents of that file::

{
"MusicCollection": [
{
"PutRequest": {
"Item": {
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Call Me Today"},
"AlbumTitle": {"S": "Somewhat Famous"}
}
}
},
{
"PutRequest": {
"Item": {
"Artist": {"S": "Acme Band"},
"SongTitle": {"S": "Happy Day"},
"AlbumTitle": {"S": "Songs About Life"}
}
}
},
{
"PutRequest": {
"Item": {
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Scared of My Shadow"},
"AlbumTitle": {"S": "Blue Sky Blues"}
}
}
}
]
}

Output::

{
"UnprocessedItems": {}
}
44 changes: 44 additions & 0 deletions awscli/examples/dynamodb/create-table.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
**To create a table**

This example creates a table named *MusicCollection*.

Command::

aws dynamodb create-table --table-name MusicCollection --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

Output::

{
"TableDescription": {
"AttributeDefinitions": [
{
"AttributeName": "Artist",
"AttributeType": "S"
},
{
"AttributeName": "SongTitle",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
},
"TableSizeBytes": 0,
"TableName": "MusicCollection",
"TableStatus": "CREATING",
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "Artist"
},
{
"KeyType": "RANGE",
"AttributeName": "SongTitle"
}
],
"ItemCount": 0,
"CreationDateTime": 1421866952.062
}
}
23 changes: 23 additions & 0 deletions awscli/examples/dynamodb/delete-item.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**To delete an item**

This example deletes an item from the *MusicCollection* table.

Command::

aws dynamodb delete-item --table-name MusicCollection --key file://key.json

The arguments for ``--key`` are stored in a JSON file, ``key.json``. Here are the contents of that file::

{
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Scared of My Shadow"}
}

Output::

{
"ConsumedCapacity": {
"CapacityUnits": 1.0,
"TableName": "MusicCollection"
}
}
23 changes: 23 additions & 0 deletions awscli/examples/dynamodb/delete-table.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**To delete a table**

This example deletes the *MusicCollection* table.

Command::

aws dynamodb delete-table --table-name MusicCollection

Output::

{
"TableDescription": {
"TableStatus": "DELETING",
"TableSizeBytes": 0,
"ItemCount": 0,
"TableName": "MusicCollection",
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
}
}
}
44 changes: 44 additions & 0 deletions awscli/examples/dynamodb/describe-table.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
**To describe a table**

This example describes the *MusicCollection* table.

Command::

aws dynamodb describe-table --table-name MusicCollection

Output::

{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "Artist",
"AttributeType": "S"
},
{
"AttributeName": "SongTitle",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
},
"TableSizeBytes": 0,
"TableName": "MusicCollection",
"TableStatus": "ACTIVE",
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "Artist"
},
{
"KeyType": "RANGE",
"AttributeName": "SongTitle"
}
],
"ItemCount": 0,
"CreationDateTime": 1421866952.062
}
}
32 changes: 32 additions & 0 deletions awscli/examples/dynamodb/get-item.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
**To read an item in a table**

This example retrieves an item from the *MusicCollection* table. The table has a hash-and-range primary key (*Artist* and *SongTitle*), so you must specify both of these ttributes.


Command::

aws dynamodb get-item --table-name MusicCollection --key file://key.json

The arguments for ``--key`` are stored in a JSON file, ``key.json``. Here are the contents of that file::

{
"Artist": {"S": "Acme Band"},
"SongTitle": {"S": "Happy Day"}
}


Output::

{
"Item": {
"AlbumTitle": {
"S": "Songs About Life"
},
"SongTitle": {
"S": "Happy Day"
},
"Artist": {
"S": "Acme Band"
}
}
}
18 changes: 18 additions & 0 deletions awscli/examples/dynamodb/list-tables.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
**To list tables**

This example lists all of the tables associated with the current AWS account and endpoint

Command::

aws dynamodb list-tables

Output::

{
"TableNames": [
"Forum",
"ProductCatalog",
"Reply",
"Thread",
]
}
24 changes: 24 additions & 0 deletions awscli/examples/dynamodb/put-item.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**To add an item to a table**

This example adds a new item to the *MusicCollection* table.

Command::

aws dynamodb put-item --table-name MusicCollection --item file://item.json --return-consumed-capacity TOTAL

The arguments for ``--item`` are stored in a JSON file, ``item.json``. Here are the contents of that file::

{
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Call Me Today"},
"AlbumTitle": {"S": "Somewhat Famous"}
}

Output::

{
"ConsumedCapacity": {
"CapacityUnits": 1.0,
"TableName": "MusicCollection"
}
}
38 changes: 38 additions & 0 deletions awscli/examples/dynamodb/query.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
**To query an item**

This example queries items in the *MusicCollection* table. The table has a hash-and-range primary key (*Artist* and *SongTitle*), but this query only specifies the hash key value. It returns song titles by the artist named "No One You Know".

Command::

aws dynamodb query --table-name MusicCollection --key-conditions file://key-conditions.json --projection-expression "SongTitle"

The arguments for ``--key-conditions`` are stored in a JSON file, ``key-conditions.json``. Here are the contents of that file::

{
"Artist": {
"AttributeValueList": [
{"S": "No One You Know"}
],
"ComparisonOperator": "EQ"
}
}

Output::

{
"Count": 2,
"Items": [
{
"SongTitle": {
"S": "Call Me Today"
}
},
{
"SongTitle": {
"S": "Scared of My Shadow"
}
}
],
"ScannedCount": 2,
"ConsumedCapacity": null
}
Loading

0 comments on commit 2956ab5

Please sign in to comment.