Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated files for DynamoDB follow along #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions DynamoDB/item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Name": { "S": "USS Okinawa" },
"Registry": { "S": "NCC-13958" },
"ShipClass": { "S": "Excelsior" },
"Description": {
"S": "Ship commanded by Admiral James Leyton and on which Benjamin Sisko served as first officer."
}
}
4 changes: 4 additions & 0 deletions DynamoDB/key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Registry": { "S": "NCC-13958" },
"ShipClass": { "S": "Excelsior" }
}
14 changes: 14 additions & 0 deletions DynamoDB/request-items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Starships": {
"Keys": [
{
"Registry": { "S": "NCC-13958" },
"ShipClass": { "S": "Excelsior" }
},
{
"Registry": { "S": "NCC-1864" },
"ShipClass": { "S": "Miranda" }
}
]
}
}
69 changes: 69 additions & 0 deletions DynamoDB/scratchpad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
## Create DynamoDB Table
aws dynamodb create-table \
--table-name Starships \
--attribute-definitions \
AttributeName=ShipClass,AttributeType=S \
AttributeName=Registry,AttributeType=S \
--key-schema \
AttributeName=ShipClass,KeyType=HASH \
AttributeName=Registry,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--region us-east-1

## Describe the table
aws dynamodb describe-table --table-name Starships --output table

## Batch-Write-Item
aws dynamodb batch-write-item --request-items file://batches/batch-000.json
aws dynamodb batch-write-item --request-items file://batches/batch-001.json
aws dynamodb batch-write-item --request-items file://batches/batch-002.json
aws dynamodb batch-write-item --request-items file://batches/batch-003.json
aws dynamodb batch-write-item --request-items file://batches/batch-004.json
aws dynamodb batch-write-item --request-items file://batches/batch-005.json
aws dynamodb batch-write-item --request-items file://batches/batch-006.json
aws dynamodb batch-write-item --request-items file://batches/batch-007.json
aws dynamodb batch-write-item --request-items file://batches/batch-008.json
aws dynamodb batch-write-item --request-items file://batches/batch-009.json
aws dynamodb batch-write-item --request-items file://batches/batch-010.json
aws dynamodb batch-write-item --request-items file://batches/batch-011.json
aws dynamodb batch-write-item --request-items file://batches/batch-012.json

## Get-Item
aws dynamodb get-item --table-name Starships --key file://key.json

## Batch-Get-Item
aws dynamodb batch-get-item --request-items file://request-items.json

## Delete-Item
aws dynamodb delete-item --table-name Starships --key file://key.json

## Put-Item
aws dynamodb put-item --table-name Starships --item file://item.json

## Update-Item
aws dynamodb update-item \
--table-name Starships \
--key file://key.json \
--update-expression "Set #D = :D" \
--expression-attribute-names file://expression-attribute-names.json \
--expression-attribute-values file://expression-attribute-values.json \
--return-values ALL_NEW

## Scan
aws dynamodb scan \
--table-name Starships \
--filter-expression "begins_with(Description, :D)" \
--expression-attribute-values '{":D": {"S": "Destroyed"}}'

## Query
aws dynamodb query \
--table-name Starships \
--key-condition-expression "ShipClass = :C" \
--expression-attribute-values '{":C": {"S": "Galaxy"}}'

## Transact
aws dynamodb transact-get-items \
--transact-items file://transact-get-items.json

aws dynamodb transact-write-items \
--transact-items file://transact-write-items.json
20 changes: 20 additions & 0 deletions DynamoDB/transact-get-items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"Get": {
"Key": {
"Artist": { "S": "Acme Band" },
"SongTitle": { "S": "Happy Day" }
},
"TableName": "MusicCollection"
}
},
{
"Get": {
"Key": {
"Artist": { "S": "No One You Know" },
"SongTitle": { "S": "Call Me Today" }
},
"TableName": "MusicCollection"
}
}
]
26 changes: 26 additions & 0 deletions DynamoDB/transact-write-items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"Update": {
"Key": {
"Artist": { "S": "Acme Band" },
"SongTitle": { "S": "Happy Day" }
},
"UpdateExpression": "SET AlbumTitle = :newval",
"ExpressionAttributeValues": {
":newval": { "S": "Updated Album Title" }
},
"TableName": "MusicCollection",
"ConditionExpression": "attribute_not_exists(Rating)"
}
},
{
"Delete": {
"Key": {
"Artist": { "S": "No One You Know" },
"SongTitle": { "S": "Call Me Today" }
},
"TableName": "MusicCollection",
"ConditionExpression": "attribute_not_exists(Rating)"
}
}
]