Created
July 1, 2025 23:32
-
-
Save recalde/319742f5a8477caa4df893bb9bea4da7 to your computer and use it in GitHub Desktop.
enable_dynamodb_streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Constants | |
TABLE_PREFIX="clean_tbl" | |
LAMBDA_NAME="lambda_stream_parquet" | |
REGION="us-east-1" # Change if needed | |
# Get Lambda ARN | |
LAMBDA_ARN=$(aws lambda get-function --function-name "$LAMBDA_NAME" --region "$REGION" --query 'Configuration.FunctionArn' --output text) | |
if [[ -z "$LAMBDA_ARN" ]]; then | |
echo "β Could not find Lambda function: $LAMBDA_NAME" | |
exit 1 | |
fi | |
echo "π Lambda ARN: $LAMBDA_ARN" | |
# Get all table names and filter by prefix | |
TABLES=$(aws dynamodb list-tables --region "$REGION" --query "TableNames[?starts_with(@, '$TABLE_PREFIX')]" --output text) | |
if [[ -z "$TABLES" ]]; then | |
echo "β οΈ No DynamoDB tables found with prefix $TABLE_PREFIX" | |
exit 0 | |
fi | |
for TABLE_NAME in $TABLES; do | |
echo "π Processing table: $TABLE_NAME" | |
# Enable stream on the table | |
echo "π οΈ Enabling stream (NEW_AND_OLD_IMAGES)..." | |
aws dynamodb update-table \ | |
--table-name "$TABLE_NAME" \ | |
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \ | |
--region "$REGION" | |
# Get stream ARN | |
STREAM_ARN=$(aws dynamodb describe-table --table-name "$TABLE_NAME" \ | |
--region "$REGION" \ | |
--query "Table.LatestStreamArn" --output text) | |
if [[ -z "$STREAM_ARN" ]]; then | |
echo "β Failed to retrieve stream ARN for $TABLE_NAME" | |
continue | |
fi | |
echo "π Stream ARN: $STREAM_ARN" | |
# Create event source mapping | |
echo "π Creating event source mapping..." | |
aws lambda create-event-source-mapping \ | |
--function-name "$LAMBDA_NAME" \ | |
--event-source-arn "$STREAM_ARN" \ | |
--starting-position LATEST \ | |
--region "$REGION" | |
echo "β Stream enabled and Lambda mapping created for $TABLE_NAME" | |
done | |
echo "π Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment