In this video we will create a DynamoDB Database using the AWS CLI.
Instructions on installing the AWS CLI:: https://docs.aws.amazon.com/cli/lates...
Commands used in this video:
get the default region
aws configure get default.region
dynamodb cli help
aws dynamodb help
create a table with the Primary Key of "author" (partition key) and "title" (sort key):
aws dynamodb create-table \
--table-name books \
--attribute-definitions AttributeName=author,AttributeType=S AttributeName=title,AttributeType=S \
--key-schema AttributeName=author,KeyType=HASH AttributeName=title,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
list tables
add an item to the table
aws dynamodb put-item \
--table-name books \
--item '{
"author": {"S": "tom"},
"title": {"S": "book 1"},
"yearPublished": {"N": "2000"}
}' \
--return-consumed-capacity TOTAL
list items in your table
aws dynamodb scan --table-name books
put another item in the table
aws dynamodb put-item \
--table-name books \
--item '{
"author": {"S": "tom"},
"title": {"S": "book 2"},
"published": {"N": "2000"}
}' \
--return-consumed-capacity TOTAL
remove the attribute "published" from an item
aws dynamodb update-item \
--table-name books \
--key '{"author":{"S":"tom"},"title":{"S":"book 2"}}' \
--update-expression 'REMOVE published' \
--return-values ALL_NEW \
--return-consumed-capacity TOTAL
update an item to add the yearPublished attribute
aws dynamodb update-item \
--table-name books \
--key '{"author":{"S":"tom"},"title":{"S":"book 2"}}' \
--update-expression 'SET yearPublished = :t' \
--expression-attribute-values '{":t" : { "N": "1989" } }' \
--return-values ALL_NEW \
--return-consumed-capacity TOTAL
update an item to add publish date, display only updated values
aws dynamodb update-item \
--table-name books \
--key '{"author":{"S":"tom"},"title":{"S":"book 2"}}' \
--update-expression 'SET yearPublished = :t' \
--expression-attribute-values '{":t" : { "N": "1900" } }' \
--return-values UPDATED_NEW \
--return-consumed-capacity TOTAL
json file contents for batch write command below
{
"books": [
{
"PutRequest": {
"Item": {
"author": {
"S": "jane"
},
"title": {
"S": "my first book"
},
"yearPublished": {
"N": "2000"
}
}
}
},
{
"PutRequest": {
"Item": {
"author": {
"S": "jane"
},
"title": {
"S": "my second book"
},
"yearPublished": {
"N": "2001"
}
}
}
}
]
}
batch write an item from a json file
aws dynamodb batch-write-item --request-items file://books.json \
--return-consumed-capacity TOTAL
this doesn't work as we need to include the entire primary key, not just part of it
aws dynamodb get-item \
--table-name books \
--key '{"author":{"S":"tom"}}'
projection-expression allows us to retrieve only specific values
aws dynamodb get-item \
--table-name books \
--key '{"author":{"S":"tom"},"title":{"S":"book 1"}}' \
--consistent-read \
--projection-expression "title" \
--return-consumed-capacity TOTAL
another projection-expression example where we retrieve two values
aws dynamodb get-item \
--table-name books \
--key '{"author":{"S":"tom"},"title":{"S":"book 1"}}' \
--consistent-read \
--projection-expression "title,yearPublished" \
--return-consumed-capacity TOTAL
example query where we query by the partition key
aws dynamodb query \
--table-name books \
--key-condition-expression "author = :name" \
--expression-attribute-values '{":name":{"S":"tom"}}'
example query using hte partition key and sort key
aws dynamodb query \
--table-name books \
--key-condition-expression "author = :name" \
--expression-attribute-values '{":name":{"S":"jane"}}'
display information about the table
aws dynamodb describe-table --table-name books
delete an item from the database using the partition and sort key
aws dynamodb delete-item --table-name books \
--key '{"author":{"S":"tom"},"title":{"S":"book 2"}}' \
--return-value ALL_OLD
delete the entire table
aws dynamodb delete-table --table-name books
In questa pagina del sito puoi guardare il video online AWS DynamoDB CLI Tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato In The Cloud 11 giugno 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 4,394 volte e gli è piaciuto 37 spettatori. Buona visione!