Skip to content

Instantly share code, notes, and snippets.

@RaphaelManke
Last active June 3, 2022 12:16
Show Gist options
  • Save RaphaelManke/b1294b537f171f4bcd1bf73eeae8782f to your computer and use it in GitHub Desktop.
Save RaphaelManke/b1294b537f171f4bcd1bf73eeae8782f to your computer and use it in GitHub Desktop.
step by step guide how to restore a dynamodb table into an existing stack. Example after refactoring the cdk code structure.

Restore DynamoDB in cdk

  1. create a backup of the old table
aws dynamodb create-backup --table-name <old-table-name> --backup-name <some-backup-name>

and remember the arn of the backup -> BACKUP_ARN

  1. deploy the cdk app with the new target table. This table will be empty.
cdk deploy
  1. get the table name of the target table -> TARGET_TABLE
  2. delete the target table
aws dynamodb delete-table --table-name <TARGET_TABLE>
  1. restore the table backup
aws dynamodb restore-table-from-backup \                                                                           
    --target-table-name <TARGET_TABLE> \
    --backup-arn <BACKUP_ARN>
  1. wait until database is restored
  2. (optional) run cloudformation drift detection or cdk diff to make sure everythin is up-to-data
@mickeelm
Copy link

Works like a charm, thank you very much! ⭐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment