Created
March 26, 2020 00:13
-
-
Save michiel/52670434b48466aef225bfd2a208d12e to your computer and use it in GitHub Desktop.
Export and import DynamoDB data across environments
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/sh | |
SOURCE_TABLE=xxx-mydata-accp | |
TARGET_TABLE=xxx-mydata-prod | |
AWS_PROFILE=default | |
AWS_REGION=ap-southeast-2 | |
# Step 1 - export and transform | |
aws --profile=$AWS_PROFILE \ | |
--region=$AWS_REGION \ | |
dynamodb scan \ | |
--table-name $SOURCE_TABLE \ | |
| jq '{"$TARGET_TABLE": [.Items[] | {PutRequest: {Item: .}}]}' > export.json | |
# Step 2 - import data | |
aws --profile=$AWS_PROFILE \ | |
--region=$AWS_REGION \ | |
dynamodb batch-write-item \ | |
--request-items export.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment