Skip to content

Instantly share code, notes, and snippets.

@klang
Created April 10, 2015 09:04
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save klang/3fe2f10ce932b9baaba1 to your computer and use it in GitHub Desktop.
Save klang/3fe2f10ce932b9baaba1 to your computer and use it in GitHub Desktop.
Example usage of DynamoDB from the cli (inside emacs, via org-mode)

Set up the environment

(setq org-confirm-babel-evaluate nil)
(setq org-babel-sh-command "ssh default ")
;; customize the following variables:
;;(setq org-babel-load-languages 
;;<<< '((emacs-lisp . t) (python . t) (clojure . t) (sh . t ) (perl . t)))
(setq org-babel-default-header-args:screen
      '((:results . "raw")
        (:session . "default")
        (:cmd . "bash")
        (:terminal . "/opt/X11/bin/xterm")))
(setq org-babel-screen-location "/usr/bin/screen")

Set up the aws command to communicate with the correct account

echo "[default]" > ~/.aws/config
echo "region = eu-west-1" >> ~/.aws/config
grep aws_access_key_id ~/.boto-dashsoftexp >> ~/.aws/config
grep aws_secret_access_key ~/.boto-dashsoftexp >> ~/.aws/config
ls -la 

remove the MusicCollection table

Press “Ctrl-c c” in the BEGIN_SRC block to activate

aws dynamodb delete-table --table-name MusicCollection

create the MusicCollection table

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

List tables

aws dynamodb list-tables

put items into the table

aws dynamodb put-item \
    --table-name MusicCollection \
    --item '{ 
        "Artist": {"S": "No One You Know"}, 
        "SongTitle": {"S": "Call Me Today"} , 
        "AlbumTitle": {"S": "Somewhat Famous"} }' \
    --return-consumed-capacity TOTAL 

> > > > > { “ConsumedCapacity”: { “TableName”: “MusicCollection”, “CapacityUnits”: 1.0 } }

aws dynamodb put-item \
    --table-name MusicCollection \
    --item '{ 
        "Artist": {"S": "Acme Band"}, 
        "SongTitle": {"S": "Happy Day"} , 
        "AlbumTitle": {"S": "Songs About Life"} }' \
    --return-consumed-capacity TOTAL

> > > > > { “ConsumedCapacity”: { “TableName”: “MusicCollection”, “CapacityUnits”: 1.0 } }

add key conditions to the table

file:key-conditions.json

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

Using DynamoDB Local

–endpoint-url has to be specified with each CLI call

aws dynamodb list-tables --endpoint-url http://localhost:8000
{
"Artist": {
"AttributeValueList": [
{
"S": "No One You Know"
}
],
"ComparisonOperator": "EQ"
},
"SongTitle": {
"AttributeValueList": [
{
"S": "Call Me Today"
}
],
"ComparisonOperator": "EQ"
}
}
@klang
Copy link
Author

klang commented Apr 10, 2015

The raw version of dynamodb.txt can be executed step by step from within Emacs. Remember that 'aws-cli' has to be present on the host computer.

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