Skip to content

Instantly share code, notes, and snippets.

@michiel
Created March 26, 2020 00:13
Show Gist options
  • Save michiel/52670434b48466aef225bfd2a208d12e to your computer and use it in GitHub Desktop.
Save michiel/52670434b48466aef225bfd2a208d12e to your computer and use it in GitHub Desktop.

Revisions

  1. michiel created this gist Mar 26, 2020.
    21 changes: 21 additions & 0 deletions transport-dynamodb-data.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/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