aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.56k stars 3.87k forks source link

(aws-dynamodb): DeletionPolicy is not propagated to replicas #17011

Open TheSPD opened 2 years ago

TheSPD commented 2 years ago

What is the problem?

When a Table is created with multiple replicationRegions, the retention policy is not propagated to the Custom::DynamoDBReplica resources that get created under cloudformation.

Reproduction Steps

  1. Create a table using with multiple replica regions
.
.
new Table(stack, 'Table', {
      partitionKey: {
        name: 'id',
        type: AttributeType.STRING,
      },
      replicationRegions: [
        'eu-west-2',
        'eu-central-1',
      ],
      removalPolicy: RemovalPolicy.RETAIN,
});
.
.  
  1. Deploy CDK Stack
  2. Remove Table from code and redeploy CDK Stack

What did you expect to happen?

we expect the table in main region as well as the replicas to be retained after removing the CDK resource.

What actually happened?

we see that the table in main region is retained but the replicas are deleted after removing the CDK resource.

CDK CLI Version

1.126.0

Framework Version

No response

Node.js Version

14.16.1

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

jakepearson commented 2 years ago

Hi, is there any update on this ticket?

Goncharo commented 1 year ago

Related to #18582 - here it's the PITR setting that is not propagated to replica tables.

rix0rrr commented 1 year ago

This issue was for the existing Table construct, which used custom resources to implement table replication. We no longer recommend the use of the Table construct.

Instead, the TableV2 construct has been released in 2.95.1 (#27023) which maps to the AWS::DynamoDB::GlobalTable resource, has better support for replication and does not suffer from the issue described here.


Be aware that there are additional deployment steps involved in a migration from Table to TableV2. You need to do a RETAIN deployment, a delete deployment, then change the code to use TableV2 and then use cdk import. A link to a full guide will be posted once it is available.

Here are some other resources to get you started (using CfnGlobalTable instead of TableV2) if you want to get going on the migration: