From 92488e1f18086412a5e9c43f006a421ed86dd797 Mon Sep 17 00:00:00 2001 From: Michael Wunderlich Date: Tue, 14 Apr 2026 16:35:00 +0000 Subject: [PATCH 1/3] Add database tutorials (batch 10) --- tuts/153-dynamodb-streams/dynamodb-streams.sh | 22 ++++++++++++++++ .../dynamodb-global-tables.sh | 21 ++++++++++++++++ tuts/164-rds-snapshots/rds-snapshots.sh | 13 ++++++++++ tuts/168-dynamodb-queries/dynamodb-queries.sh | 23 +++++++++++++++++ tuts/173-dynamodb-ttl/dynamodb-ttl.sh | 25 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 tuts/153-dynamodb-streams/dynamodb-streams.sh create mode 100644 tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh create mode 100644 tuts/164-rds-snapshots/rds-snapshots.sh create mode 100644 tuts/168-dynamodb-queries/dynamodb-queries.sh create mode 100644 tuts/173-dynamodb-ttl/dynamodb-ttl.sh diff --git a/tuts/153-dynamodb-streams/dynamodb-streams.sh b/tuts/153-dynamodb-streams/dynamodb-streams.sh new file mode 100644 index 00000000..bdcf7376 --- /dev/null +++ b/tuts/153-dynamodb-streams/dynamodb-streams.sh @@ -0,0 +1,22 @@ +#!/bin/bash +WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ddb-streams.log") 2>&1 +REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-stream-${RANDOM_ID}" +handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR +cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } +echo "Step 1: Creating table with streams enabled" +aws dynamodb create-table --table-name "$TABLE" --key-schema AttributeName=pk,KeyType=HASH --attribute-definitions AttributeName=pk,AttributeType=S --billing-mode PAY_PER_REQUEST --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES --query 'TableDescription.{Table:TableName,Stream:LatestStreamArn}' --output table +aws dynamodb wait table-exists --table-name "$TABLE" +STREAM_ARN=$(aws dynamodb describe-table --table-name "$TABLE" --query 'Table.LatestStreamArn' --output text) +echo "Step 2: Writing items to trigger stream events" +aws dynamodb put-item --table-name "$TABLE" --item '{"pk":{"S":"user-1"},"name":{"S":"Alice"},"age":{"N":"30"}}' 2>/dev/null +aws dynamodb put-item --table-name "$TABLE" --item '{"pk":{"S":"user-2"},"name":{"S":"Bob"},"age":{"N":"25"}}' 2>/dev/null +aws dynamodb update-item --table-name "$TABLE" --key '{"pk":{"S":"user-1"}}' --update-expression "SET age = :a" --expression-attribute-values '{":a":{"N":"31"}}' 2>/dev/null +aws dynamodb delete-item --table-name "$TABLE" --key '{"pk":{"S":"user-2"}}' 2>/dev/null +echo " 4 operations: 2 puts, 1 update, 1 delete" +echo "Step 3: Reading stream records" +SHARD_ID=$(aws dynamodbstreams describe-stream --stream-arn "$STREAM_ARN" --query 'StreamDescription.Shards[0].ShardId' --output text) +ITERATOR=$(aws dynamodbstreams get-shard-iterator --stream-arn "$STREAM_ARN" --shard-id "$SHARD_ID" --shard-iterator-type TRIM_HORIZON --query 'ShardIterator' --output text) +aws dynamodbstreams get-records --shard-iterator "$ITERATOR" --query 'Records[].{Event:eventName,Keys:dynamodb.Keys}' --output table +echo ""; echo "Tutorial complete." +echo "Do you want to clean up? (y/n): "; read -r CHOICE; [[ "$CHOICE" =~ ^[Yy]$ ]] && cleanup diff --git a/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh b/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh new file mode 100644 index 00000000..d9cac7b7 --- /dev/null +++ b/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh @@ -0,0 +1,21 @@ +#!/bin/bash +WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ddb-global.log") 2>&1 +REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-global-${RANDOM_ID}" +handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR +cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } +echo "Step 1: Creating table" +aws dynamodb create-table --table-name "$TABLE" --key-schema AttributeName=pk,KeyType=HASH --attribute-definitions AttributeName=pk,AttributeType=S --billing-mode PAY_PER_REQUEST --query 'TableDescription.TableName' --output text > /dev/null +aws dynamodb wait table-exists --table-name "$TABLE" +echo "Step 2: Enabling point-in-time recovery" +aws dynamodb update-continuous-backups --table-name "$TABLE" --point-in-time-recovery-specification PointInTimeRecoveryEnabled=true > /dev/null +echo " PITR enabled" +echo "Step 3: Describing continuous backups" +aws dynamodb describe-continuous-backups --table-name "$TABLE" --query 'ContinuousBackupsDescription.{Status:ContinuousBackupsStatus,PITR:PointInTimeRecoveryDescription.PointInTimeRecoveryStatus}' --output table +echo "Step 4: Writing and reading items" +aws dynamodb put-item --table-name "$TABLE" --item '{"pk":{"S":"item-1"},"data":{"S":"Hello"}}' 2>/dev/null +aws dynamodb get-item --table-name "$TABLE" --key '{"pk":{"S":"item-1"}}' --query 'Item.{pk:pk.S,data:data.S}' --output table +echo "Step 5: Table details" +aws dynamodb describe-table --table-name "$TABLE" --query 'Table.{Name:TableName,Status:TableStatus,Items:ItemCount,Billing:BillingModeSummary.BillingMode}' --output table +echo ""; echo "Tutorial complete." +echo "Do you want to clean up? (y/n): "; read -r CHOICE; [[ "$CHOICE" =~ ^[Yy]$ ]] && cleanup diff --git a/tuts/164-rds-snapshots/rds-snapshots.sh b/tuts/164-rds-snapshots/rds-snapshots.sh new file mode 100644 index 00000000..876f497a --- /dev/null +++ b/tuts/164-rds-snapshots/rds-snapshots.sh @@ -0,0 +1,13 @@ +#!/bin/bash +WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/rds-snap.log") 2>&1 +REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +echo "Step 1: Listing RDS instances" +aws rds describe-db-instances --query 'DBInstances[:5].{Id:DBInstanceIdentifier,Engine:Engine,Status:DBInstanceStatus,Class:DBInstanceClass}' --output table 2>/dev/null || echo " No RDS instances" +echo "Step 2: Listing automated snapshots" +aws rds describe-db-snapshots --snapshot-type automated --query 'DBSnapshots[:5].{Id:DBSnapshotIdentifier,Instance:DBInstanceIdentifier,Status:Status,Engine:Engine}' --output table 2>/dev/null || echo " No automated snapshots" +echo "Step 3: Listing manual snapshots" +aws rds describe-db-snapshots --snapshot-type manual --query 'DBSnapshots[:5].{Id:DBSnapshotIdentifier,Status:Status,Size:AllocatedStorage}' --output table 2>/dev/null || echo " No manual snapshots" +echo "Step 4: Listing cluster snapshots" +aws rds describe-db-cluster-snapshots --query 'DBClusterSnapshots[:3].{Id:DBClusterSnapshotIdentifier,Cluster:DBClusterIdentifier,Status:Status}' --output table 2>/dev/null || echo " No cluster snapshots" +echo ""; echo "Tutorial complete. No resources created — read-only." +rm -rf "$WORK_DIR" diff --git a/tuts/168-dynamodb-queries/dynamodb-queries.sh b/tuts/168-dynamodb-queries/dynamodb-queries.sh new file mode 100644 index 00000000..eafb4744 --- /dev/null +++ b/tuts/168-dynamodb-queries/dynamodb-queries.sh @@ -0,0 +1,23 @@ +#!/bin/bash +WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ddb-query.log") 2>&1 +REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-query-${RANDOM_ID}" +handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR +cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } +echo "Step 1: Creating table with GSI" +aws dynamodb create-table --table-name "$TABLE" --key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE --attribute-definitions AttributeName=pk,AttributeType=S AttributeName=sk,AttributeType=S AttributeName=status,AttributeType=S --billing-mode PAY_PER_REQUEST --global-secondary-indexes '[{"IndexName":"status-index","KeySchema":[{"AttributeName":"status","KeyType":"HASH"},{"AttributeName":"sk","KeyType":"RANGE"}],"Projection":{"ProjectionType":"ALL"}}]' > /dev/null +aws dynamodb wait table-exists --table-name "$TABLE" +echo "Step 2: Writing items" +for i in 1 2 3 4 5; do + STATUS=$( [ $((i % 2)) -eq 0 ] && echo "active" || echo "inactive" ) + aws dynamodb put-item --table-name "$TABLE" --item "{\"pk\":{\"S\":\"user-$i\"},\"sk\":{\"S\":\"profile\"},\"name\":{\"S\":\"User $i\"},\"status\":{\"S\":\"$STATUS\"}}" 2>/dev/null +done +echo " Wrote 5 items" +echo "Step 3: Query by partition key" +aws dynamodb query --table-name "$TABLE" --key-condition-expression "pk = :pk" --expression-attribute-values '{":pk":{"S":"user-1"}}' --query 'Items[].{pk:pk.S,name:name.S,status:status.S}' --output table +echo "Step 4: Query GSI (active users)" +aws dynamodb query --table-name "$TABLE" --index-name status-index --key-condition-expression "#s = :s" --expression-attribute-names '{"#s":"status"}' --expression-attribute-values '{":s":{"S":"active"}}' --query 'Items[].{pk:pk.S,name:name.S}' --output table +echo "Step 5: Scan with filter" +aws dynamodb scan --table-name "$TABLE" --filter-expression "#s = :s" --expression-attribute-names '{"#s":"status"}' --expression-attribute-values '{":s":{"S":"inactive"}}' --query '{Count:Count,Items:Items[].{pk:pk.S,name:name.S}}' --output table +echo ""; echo "Tutorial complete." +echo "Do you want to clean up? (y/n): "; read -r CHOICE; [[ "$CHOICE" =~ ^[Yy]$ ]] && cleanup diff --git a/tuts/173-dynamodb-ttl/dynamodb-ttl.sh b/tuts/173-dynamodb-ttl/dynamodb-ttl.sh new file mode 100644 index 00000000..d4f35f1b --- /dev/null +++ b/tuts/173-dynamodb-ttl/dynamodb-ttl.sh @@ -0,0 +1,25 @@ +#!/bin/bash +WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ttl.log") 2>&1 +REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-ttl-${RANDOM_ID}" +handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR +cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } +echo "Step 1: Creating table" +aws dynamodb create-table --table-name "$TABLE" --key-schema AttributeName=pk,KeyType=HASH --attribute-definitions AttributeName=pk,AttributeType=S --billing-mode PAY_PER_REQUEST > /dev/null +aws dynamodb wait table-exists --table-name "$TABLE" +echo "Step 2: Enabling TTL" +aws dynamodb update-time-to-live --table-name "$TABLE" --time-to-live-specification Enabled=true,AttributeName=expires_at > /dev/null +echo " TTL enabled on 'expires_at' attribute" +echo "Step 3: Writing items with TTL" +PAST=$(($(date +%s) - 3600)) +FUTURE=$(($(date +%s) + 86400)) +aws dynamodb put-item --table-name "$TABLE" --item "{\"pk\":{\"S\":\"expired-item\"},\"data\":{\"S\":\"This should expire\"},\"expires_at\":{\"N\":\"$PAST\"}}" 2>/dev/null +aws dynamodb put-item --table-name "$TABLE" --item "{\"pk\":{\"S\":\"active-item\"},\"data\":{\"S\":\"This stays\"},\"expires_at\":{\"N\":\"$FUTURE\"}}" 2>/dev/null +echo " Wrote 2 items (1 expired, 1 active)" +echo "Step 4: Describing TTL" +aws dynamodb describe-time-to-live --table-name "$TABLE" --query 'TimeToLiveDescription.{Status:TimeToLiveStatus,Attribute:AttributeName}' --output table +echo "Step 5: Scanning items" +aws dynamodb scan --table-name "$TABLE" --query 'Items[].{pk:pk.S,data:data.S,expires:expires_at.N}' --output table +echo " Note: DynamoDB deletes expired items within 48 hours, not immediately" +echo ""; echo "Tutorial complete." +echo "Do you want to clean up? (y/n): "; read -r CHOICE; [[ "$CHOICE" =~ ^[Yy]$ ]] && cleanup From 3a3bd5e779828f0d203578dcbd029e00de904dc4 Mon Sep 17 00:00:00 2001 From: Michael Wunderlich Date: Tue, 21 Apr 2026 05:17:16 +0000 Subject: [PATCH 2/3] Apply technical requirements (R1, R2, R9, R10, R13) - R1: Add AWS_REGION to region fallback chain - R2: Replace openssl rand with /dev/urandom - R9: Remove Appendix/Generation details from READMEs - R10: Remove internal references - R13: Add REVISION-HISTORY.md --- tuts/153-dynamodb-streams/REVISION-HISTORY.md | 8 ++++++++ tuts/153-dynamodb-streams/dynamodb-streams.sh | 4 ++-- tuts/162-dynamodb-continuous-backups/REVISION-HISTORY.md | 8 ++++++++ .../dynamodb-global-tables.sh | 4 ++-- tuts/164-rds-snapshots/REVISION-HISTORY.md | 8 ++++++++ tuts/164-rds-snapshots/rds-snapshots.sh | 2 +- tuts/168-dynamodb-queries/REVISION-HISTORY.md | 8 ++++++++ tuts/168-dynamodb-queries/dynamodb-queries.sh | 4 ++-- tuts/173-dynamodb-ttl/REVISION-HISTORY.md | 8 ++++++++ tuts/173-dynamodb-ttl/dynamodb-ttl.sh | 4 ++-- 10 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 tuts/153-dynamodb-streams/REVISION-HISTORY.md create mode 100644 tuts/162-dynamodb-continuous-backups/REVISION-HISTORY.md create mode 100644 tuts/164-rds-snapshots/REVISION-HISTORY.md create mode 100644 tuts/168-dynamodb-queries/REVISION-HISTORY.md create mode 100644 tuts/173-dynamodb-ttl/REVISION-HISTORY.md diff --git a/tuts/153-dynamodb-streams/REVISION-HISTORY.md b/tuts/153-dynamodb-streams/REVISION-HISTORY.md new file mode 100644 index 00000000..282b695f --- /dev/null +++ b/tuts/153-dynamodb-streams/REVISION-HISTORY.md @@ -0,0 +1,8 @@ +# Revision History: 153-dynamodb-streams + +## Shell (CLI script) + +### 2026-04-14 v1 published +- Type: functional +- Initial version + diff --git a/tuts/153-dynamodb-streams/dynamodb-streams.sh b/tuts/153-dynamodb-streams/dynamodb-streams.sh index bdcf7376..cb69c4bb 100644 --- a/tuts/153-dynamodb-streams/dynamodb-streams.sh +++ b/tuts/153-dynamodb-streams/dynamodb-streams.sh @@ -1,7 +1,7 @@ #!/bin/bash WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ddb-streams.log") 2>&1 -REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" -RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-stream-${RANDOM_ID}" +REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null))}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1); TABLE="tut-stream-${RANDOM_ID}" handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } echo "Step 1: Creating table with streams enabled" diff --git a/tuts/162-dynamodb-continuous-backups/REVISION-HISTORY.md b/tuts/162-dynamodb-continuous-backups/REVISION-HISTORY.md new file mode 100644 index 00000000..2db13500 --- /dev/null +++ b/tuts/162-dynamodb-continuous-backups/REVISION-HISTORY.md @@ -0,0 +1,8 @@ +# Revision History: 162-dynamodb-continuous-backups + +## Shell (CLI script) + +### 2026-04-14 v1 published +- Type: functional +- Initial version + diff --git a/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh b/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh index d9cac7b7..d838d99f 100644 --- a/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh +++ b/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.sh @@ -1,7 +1,7 @@ #!/bin/bash WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ddb-global.log") 2>&1 -REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" -RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-global-${RANDOM_ID}" +REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null))}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1); TABLE="tut-global-${RANDOM_ID}" handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } echo "Step 1: Creating table" diff --git a/tuts/164-rds-snapshots/REVISION-HISTORY.md b/tuts/164-rds-snapshots/REVISION-HISTORY.md new file mode 100644 index 00000000..99d6de2c --- /dev/null +++ b/tuts/164-rds-snapshots/REVISION-HISTORY.md @@ -0,0 +1,8 @@ +# Revision History: 164-rds-snapshots + +## Shell (CLI script) + +### 2026-04-14 v1 published +- Type: functional +- Initial version + diff --git a/tuts/164-rds-snapshots/rds-snapshots.sh b/tuts/164-rds-snapshots/rds-snapshots.sh index 876f497a..4be7c8a8 100644 --- a/tuts/164-rds-snapshots/rds-snapshots.sh +++ b/tuts/164-rds-snapshots/rds-snapshots.sh @@ -1,6 +1,6 @@ #!/bin/bash WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/rds-snap.log") 2>&1 -REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null))}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" echo "Step 1: Listing RDS instances" aws rds describe-db-instances --query 'DBInstances[:5].{Id:DBInstanceIdentifier,Engine:Engine,Status:DBInstanceStatus,Class:DBInstanceClass}' --output table 2>/dev/null || echo " No RDS instances" echo "Step 2: Listing automated snapshots" diff --git a/tuts/168-dynamodb-queries/REVISION-HISTORY.md b/tuts/168-dynamodb-queries/REVISION-HISTORY.md new file mode 100644 index 00000000..35eac78b --- /dev/null +++ b/tuts/168-dynamodb-queries/REVISION-HISTORY.md @@ -0,0 +1,8 @@ +# Revision History: 168-dynamodb-queries + +## Shell (CLI script) + +### 2026-04-14 v1 published +- Type: functional +- Initial version + diff --git a/tuts/168-dynamodb-queries/dynamodb-queries.sh b/tuts/168-dynamodb-queries/dynamodb-queries.sh index eafb4744..ac08ff3c 100644 --- a/tuts/168-dynamodb-queries/dynamodb-queries.sh +++ b/tuts/168-dynamodb-queries/dynamodb-queries.sh @@ -1,7 +1,7 @@ #!/bin/bash WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ddb-query.log") 2>&1 -REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" -RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-query-${RANDOM_ID}" +REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null))}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1); TABLE="tut-query-${RANDOM_ID}" handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } echo "Step 1: Creating table with GSI" diff --git a/tuts/173-dynamodb-ttl/REVISION-HISTORY.md b/tuts/173-dynamodb-ttl/REVISION-HISTORY.md new file mode 100644 index 00000000..03502a9b --- /dev/null +++ b/tuts/173-dynamodb-ttl/REVISION-HISTORY.md @@ -0,0 +1,8 @@ +# Revision History: 173-dynamodb-ttl + +## Shell (CLI script) + +### 2026-04-14 v1 published +- Type: functional +- Initial version + diff --git a/tuts/173-dynamodb-ttl/dynamodb-ttl.sh b/tuts/173-dynamodb-ttl/dynamodb-ttl.sh index d4f35f1b..841f074f 100644 --- a/tuts/173-dynamodb-ttl/dynamodb-ttl.sh +++ b/tuts/173-dynamodb-ttl/dynamodb-ttl.sh @@ -1,7 +1,7 @@ #!/bin/bash WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/ttl.log") 2>&1 -REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" -RANDOM_ID=$(openssl rand -hex 4); TABLE="tut-ttl-${RANDOM_ID}" +REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null))}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION" +RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1); TABLE="tut-ttl-${RANDOM_ID}" handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR cleanup() { echo ""; echo "Cleaning up..."; aws dynamodb delete-table --table-name "$TABLE" > /dev/null 2>&1 && echo " Deleted table"; rm -rf "$WORK_DIR"; echo "Done."; } echo "Step 1: Creating table" From 96c3be6f294c076ec58dbc5d92ad8ad8bdc05c71 Mon Sep 17 00:00:00 2001 From: Michael Wunderlich Date: Tue, 21 Apr 2026 05:38:00 +0000 Subject: [PATCH 3/3] Add README.md and tutorial walkthrough for script-only tutorials --- tuts/153-dynamodb-streams/README.md | 38 ++++++++++++++++++ tuts/153-dynamodb-streams/dynamodb-streams.md | 23 +++++++++++ .../162-dynamodb-continuous-backups/README.md | 39 +++++++++++++++++++ .../dynamodb-global-tables.md | 31 +++++++++++++++ tuts/164-rds-snapshots/README.md | 29 ++++++++++++++ tuts/164-rds-snapshots/rds-snapshots.md | 23 +++++++++++ tuts/168-dynamodb-queries/README.md | 39 +++++++++++++++++++ tuts/168-dynamodb-queries/dynamodb-queries.md | 31 +++++++++++++++ tuts/173-dynamodb-ttl/README.md | 39 +++++++++++++++++++ tuts/173-dynamodb-ttl/dynamodb-ttl.md | 31 +++++++++++++++ 10 files changed, 323 insertions(+) create mode 100644 tuts/153-dynamodb-streams/README.md create mode 100644 tuts/153-dynamodb-streams/dynamodb-streams.md create mode 100644 tuts/162-dynamodb-continuous-backups/README.md create mode 100644 tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.md create mode 100644 tuts/164-rds-snapshots/README.md create mode 100644 tuts/164-rds-snapshots/rds-snapshots.md create mode 100644 tuts/168-dynamodb-queries/README.md create mode 100644 tuts/168-dynamodb-queries/dynamodb-queries.md create mode 100644 tuts/173-dynamodb-ttl/README.md create mode 100644 tuts/173-dynamodb-ttl/dynamodb-ttl.md diff --git a/tuts/153-dynamodb-streams/README.md b/tuts/153-dynamodb-streams/README.md new file mode 100644 index 00000000..9e460e06 --- /dev/null +++ b/tuts/153-dynamodb-streams/README.md @@ -0,0 +1,38 @@ +# Dynamodb Streams + +An AWS CLI tutorial that demonstrates Dynamodb operations. + +## Running + +```bash +bash dynamodb-streams.sh +``` + +To auto-run with cleanup: + +```bash +echo 'y' | bash dynamodb-streams.sh +``` + +## What it does + +1. Creating table with streams enabled +2. Writing items to trigger stream events +3. Reading stream records + +## Resources created + +- Table +- Item + +The script prompts you to clean up resources when it finishes. + +## Cost + +Free tier eligible for most operations. Clean up resources after use to avoid charges. + +## Related docs + +- [AWS CLI dynamodb reference](https://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html) +- [AWS CLI dynamodbstreams reference](https://docs.aws.amazon.com/cli/latest/reference/dynamodbstreams/index.html) + diff --git a/tuts/153-dynamodb-streams/dynamodb-streams.md b/tuts/153-dynamodb-streams/dynamodb-streams.md new file mode 100644 index 00000000..d581480b --- /dev/null +++ b/tuts/153-dynamodb-streams/dynamodb-streams.md @@ -0,0 +1,23 @@ +# Dynamodb Streams + +## Prerequisites + +1. AWS CLI installed and configured (`aws configure`) +2. Appropriate IAM permissions for the AWS services used + +## Step 1: Creating table with streams enabled + +The script handles this step automatically. See `dynamodb-streams.sh` for the exact CLI commands. + +## Step 2: Writing items to trigger stream events + +The script handles this step automatically. See `dynamodb-streams.sh` for the exact CLI commands. + +## Step 3: Reading stream records + +The script handles this step automatically. See `dynamodb-streams.sh` for the exact CLI commands. + +## Cleanup + +The script prompts you to clean up all created resources. If you need to clean up manually, check the script log for the resource names that were created. + diff --git a/tuts/162-dynamodb-continuous-backups/README.md b/tuts/162-dynamodb-continuous-backups/README.md new file mode 100644 index 00000000..9bcc5ef4 --- /dev/null +++ b/tuts/162-dynamodb-continuous-backups/README.md @@ -0,0 +1,39 @@ +# Dynamodb Global Tables + +An AWS CLI tutorial that demonstrates Dynamodb operations. + +## Running + +```bash +bash dynamodb-global-tables.sh +``` + +To auto-run with cleanup: + +```bash +echo 'y' | bash dynamodb-global-tables.sh +``` + +## What it does + +1. Creating table +2. Enabling point-in-time recovery +3. Describing continuous backups +4. Writing and reading items +5. Table details + +## Resources created + +- Table +- Item + +The script prompts you to clean up resources when it finishes. + +## Cost + +Free tier eligible for most operations. Clean up resources after use to avoid charges. + +## Related docs + +- [AWS CLI dynamodb reference](https://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html) + diff --git a/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.md b/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.md new file mode 100644 index 00000000..10c7fa6a --- /dev/null +++ b/tuts/162-dynamodb-continuous-backups/dynamodb-global-tables.md @@ -0,0 +1,31 @@ +# Dynamodb Global Tables + +## Prerequisites + +1. AWS CLI installed and configured (`aws configure`) +2. Appropriate IAM permissions for the AWS services used + +## Step 1: Creating table + +The script handles this step automatically. See `dynamodb-global-tables.sh` for the exact CLI commands. + +## Step 2: Enabling point-in-time recovery + +The script handles this step automatically. See `dynamodb-global-tables.sh` for the exact CLI commands. + +## Step 3: Describing continuous backups + +The script handles this step automatically. See `dynamodb-global-tables.sh` for the exact CLI commands. + +## Step 4: Writing and reading items + +The script handles this step automatically. See `dynamodb-global-tables.sh` for the exact CLI commands. + +## Step 5: Table details + +The script handles this step automatically. See `dynamodb-global-tables.sh` for the exact CLI commands. + +## Cleanup + +The script prompts you to clean up all created resources. If you need to clean up manually, check the script log for the resource names that were created. + diff --git a/tuts/164-rds-snapshots/README.md b/tuts/164-rds-snapshots/README.md new file mode 100644 index 00000000..330a5233 --- /dev/null +++ b/tuts/164-rds-snapshots/README.md @@ -0,0 +1,29 @@ +# Rds Snapshots + +A read-only script that queries Rds resources and displays information. + +## Running + +```bash +bash rds-snapshots.sh +``` + +## What it does + +1. Listing RDS instances +2. Listing automated snapshots +3. Listing manual snapshots +4. Listing cluster snapshots + +## Resources created + +None — this script is read-only. + +## Cost + +No cost. This script only reads existing resources. + +## Related docs + +- [AWS CLI rds reference](https://docs.aws.amazon.com/cli/latest/reference/rds/index.html) + diff --git a/tuts/164-rds-snapshots/rds-snapshots.md b/tuts/164-rds-snapshots/rds-snapshots.md new file mode 100644 index 00000000..380a74ce --- /dev/null +++ b/tuts/164-rds-snapshots/rds-snapshots.md @@ -0,0 +1,23 @@ +# Rds Snapshots + +## Prerequisites + +1. AWS CLI installed and configured (`aws configure`) +2. Appropriate IAM permissions for the AWS services used + +## Step 1: Listing RDS instances + +The script handles this step automatically. See `rds-snapshots.sh` for the exact CLI commands. + +## Step 2: Listing automated snapshots + +The script handles this step automatically. See `rds-snapshots.sh` for the exact CLI commands. + +## Step 3: Listing manual snapshots + +The script handles this step automatically. See `rds-snapshots.sh` for the exact CLI commands. + +## Step 4: Listing cluster snapshots + +The script handles this step automatically. See `rds-snapshots.sh` for the exact CLI commands. + diff --git a/tuts/168-dynamodb-queries/README.md b/tuts/168-dynamodb-queries/README.md new file mode 100644 index 00000000..2187c237 --- /dev/null +++ b/tuts/168-dynamodb-queries/README.md @@ -0,0 +1,39 @@ +# Dynamodb Queries + +An AWS CLI tutorial that demonstrates Dynamodb operations. + +## Running + +```bash +bash dynamodb-queries.sh +``` + +To auto-run with cleanup: + +```bash +echo 'y' | bash dynamodb-queries.sh +``` + +## What it does + +1. Creating table with GSI +2. Writing items +3. Query by partition key +4. Query GSI (active users) +5. Scan with filter + +## Resources created + +- Table +- Item + +The script prompts you to clean up resources when it finishes. + +## Cost + +Free tier eligible for most operations. Clean up resources after use to avoid charges. + +## Related docs + +- [AWS CLI dynamodb reference](https://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html) + diff --git a/tuts/168-dynamodb-queries/dynamodb-queries.md b/tuts/168-dynamodb-queries/dynamodb-queries.md new file mode 100644 index 00000000..69b02921 --- /dev/null +++ b/tuts/168-dynamodb-queries/dynamodb-queries.md @@ -0,0 +1,31 @@ +# Dynamodb Queries + +## Prerequisites + +1. AWS CLI installed and configured (`aws configure`) +2. Appropriate IAM permissions for the AWS services used + +## Step 1: Creating table with GSI + +The script handles this step automatically. See `dynamodb-queries.sh` for the exact CLI commands. + +## Step 2: Writing items + +The script handles this step automatically. See `dynamodb-queries.sh` for the exact CLI commands. + +## Step 3: Query by partition key + +The script handles this step automatically. See `dynamodb-queries.sh` for the exact CLI commands. + +## Step 4: Query GSI (active users) + +The script handles this step automatically. See `dynamodb-queries.sh` for the exact CLI commands. + +## Step 5: Scan with filter + +The script handles this step automatically. See `dynamodb-queries.sh` for the exact CLI commands. + +## Cleanup + +The script prompts you to clean up all created resources. If you need to clean up manually, check the script log for the resource names that were created. + diff --git a/tuts/173-dynamodb-ttl/README.md b/tuts/173-dynamodb-ttl/README.md new file mode 100644 index 00000000..8e3cb7b2 --- /dev/null +++ b/tuts/173-dynamodb-ttl/README.md @@ -0,0 +1,39 @@ +# Dynamodb Ttl + +An AWS CLI tutorial that demonstrates Dynamodb operations. + +## Running + +```bash +bash dynamodb-ttl.sh +``` + +To auto-run with cleanup: + +```bash +echo 'y' | bash dynamodb-ttl.sh +``` + +## What it does + +1. Creating table +2. Enabling TTL +3. Writing items with TTL +4. Describing TTL +5. Scanning items + +## Resources created + +- Table +- Item + +The script prompts you to clean up resources when it finishes. + +## Cost + +Free tier eligible for most operations. Clean up resources after use to avoid charges. + +## Related docs + +- [AWS CLI dynamodb reference](https://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html) + diff --git a/tuts/173-dynamodb-ttl/dynamodb-ttl.md b/tuts/173-dynamodb-ttl/dynamodb-ttl.md new file mode 100644 index 00000000..7f88332c --- /dev/null +++ b/tuts/173-dynamodb-ttl/dynamodb-ttl.md @@ -0,0 +1,31 @@ +# Dynamodb Ttl + +## Prerequisites + +1. AWS CLI installed and configured (`aws configure`) +2. Appropriate IAM permissions for the AWS services used + +## Step 1: Creating table + +The script handles this step automatically. See `dynamodb-ttl.sh` for the exact CLI commands. + +## Step 2: Enabling TTL + +The script handles this step automatically. See `dynamodb-ttl.sh` for the exact CLI commands. + +## Step 3: Writing items with TTL + +The script handles this step automatically. See `dynamodb-ttl.sh` for the exact CLI commands. + +## Step 4: Describing TTL + +The script handles this step automatically. See `dynamodb-ttl.sh` for the exact CLI commands. + +## Step 5: Scanning items + +The script handles this step automatically. See `dynamodb-ttl.sh` for the exact CLI commands. + +## Cleanup + +The script prompts you to clean up all created resources. If you need to clean up manually, check the script log for the resource names that were created. +