Skip to content

Instantly share code, notes, and snippets.

@mrbitsdcf
Last active December 29, 2022 12:01
Show Gist options
  • Save mrbitsdcf/8d93c68e8164296b54d52008774fb9c1 to your computer and use it in GitHub Desktop.
Save mrbitsdcf/8d93c68e8164296b54d52008774fb9c1 to your computer and use it in GitHub Desktop.
Dump schema and use it to create AWS DynamoDB tables from one account to another
#!/bin/bash
for TBL in $(aws dynamodb list-tables --profile ABC --query "TableNames[]" --output text) ; do
echo "Doing $TBL"
aws dynamodb describe-table --table-name $TBL --profile ABC > ${TBL}.json
BILLINGMODE=$(grep -e '.*BillingMode"' ${TBL}.json | tr -d " ")
jq < ${TBL}.json ".Table | {TableName, KeySchema, AttributeDefinitions} + (try {LocalSecondaryIndexes: [ .LocalSecondaryIndexes[] | {IndexName, KeySchema, Projection} ]} // {}) + (try {GlobalSecondaryIndexes: [ .GlobalSecondaryIndexes[] | {IndexName, KeySchema, Projection} ]} // {}) + { ${BILLINGMODE} }" > create_${TBL}.json
aws dynamodb create-table --cli-input-json file://create_${TBL}.json --profile DEF
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment