Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Created July 5, 2019 13:16
Show Gist options
  • Select an option

  • Save matthewpoer/272062de02cd52709010b7251edf79da to your computer and use it in GitHub Desktop.

Select an option

Save matthewpoer/272062de02cd52709010b7251edf79da to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
PROFILE=yourFavoriteAwsProfile
REGION=us-east-1
TABLE=origin-table
DEST_TABLE=destination-table
TABLE_DUMP=$(aws dynamodb scan --profile ${PROFILE} --region ${REGION} --table-name ${TABLE})
TABLE_Items=`echo ${TABLE_DUMP} | jq -r '.Items'`
TABLE_ScannedCount=`echo ${TABLE_DUMP} | jq -r '.ScannedCount'`
TABLE_Count=`echo ${TABLE_DUMP} | jq -r '.Count'`
TABLE_LastEvaluatedKey=`echo ${TABLE_DUMP} | jq -r '.LastEvaluatedKey'`
echo "TABLE_ScannedCount: ${TABLE_ScannedCount}"
echo "TABLE_Count: ${TABLE_Count}"
echo "TABLE_LastEvaluatedKey: ${TABLE_LastEvaluatedKey}"
# iterate over TABLE_Items
for index in $(seq 0 $((TABLE_Count - 1))); do
projectId=`echo ${TABLE_Items} | jq -r ".[${index}].projectId.S"`
echo "working on project id: ${projectId}"
echo ${TABLE_Items} | jq -r ".[${index}]" > itemData.json
aws dynamodb put-item --profile ${PROFILE} --region ${REGION} --table-name ${DEST_TABLE} --item file://itemData.json
done
rm itemData.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment