Skip to content

Instantly share code, notes, and snippets.

@michiel
Created March 26, 2020 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michiel/52670434b48466aef225bfd2a208d12e to your computer and use it in GitHub Desktop.
Save michiel/52670434b48466aef225bfd2a208d12e to your computer and use it in GitHub Desktop.
Export and import DynamoDB data across environments
#!/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