Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Last active January 16, 2024 14:55
Show Gist options
  • Save mortymacs/f2a4e639a0fafb3c0e210942976fe070 to your computer and use it in GitHub Desktop.
Save mortymacs/f2a4e639a0fafb3c0e210942976fe070 to your computer and use it in GitHub Desktop.
DynamoDB aws-cli sample

Init DB

$ aws-local dynamodb create-table --cli-input-json file://test/seed/users/initdb.json

Table list

$ aws-local dynamodb list-tables

Get item

$ aws-local dynamodb get-item --table-name Users --key='{"ID": {"S": "12432242"}}'

Put item

aws-local dynamodb put-item --table-name Users --cli-input-json file://test/seed/users/user_*.json

Delete item

aws-local dynamodb delete-item --table-name User --key='{"ID": {"S": "12432242"}}'

List items

aws-local dynamodb scan --table-name User

List items (Only ID)

aws-local dynamodb scan --table-name User | jq -r '.Items.[].ID.S'

Purge table

for key in $(aws-local dynamodb scan --table-name User | jq -r '.Items.[].ID.S'); do
    aws-local dynamodb delete-item --table-name User --key="{\"ID\": {\"S\": \"$key\"}}"
done
{
"TableName": "Users",
"KeySchema": [{
"AttributeName": "ID",
"KeyType": "HASH"
}],
"AttributeDefinitions": [{
"AttributeName": "ID",
"AttributeType": "S"
}],
"ProvisionedThroughput": {
"ReadCapacityUnits": 100,
"WriteCapacityUnits": 100
}
}
{
"Item": {
"ID": {
"S": "12432242"
},
"Name": {
"S": "Test"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment