Last active
December 29, 2022 12:01
-
-
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
This file contains 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 | |
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