Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB: Global Table creation doesn't set retention policy for replica tables #25740

Closed
BalintLab opened this issue May 25, 2023 · 4 comments
Closed
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. ddb-legacy-table This issue has to do with DynamoDB's legacy Table construct. Close after migration guide is out. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@BalintLab
Copy link

Status

Investigating (Default)

What is the issue?

The level 2 Table construct creates global tables that are not in alignment with DynamoDB best practices (uses Table CFN resource + custom resources vs the GlobalTable CFN resource)

This poses a serious risk of deleting the replicas if their retain policy was set up on the construct:

const XRTable2_lvl2 = new Table(this, 'Table', {
   tableName: "XRTable2_lvl2",
   partitionKey: { name: 'id', type: AttributeType.STRING },
   replicationRegions: ['us-east-1', 'us-east-2', 'us-west-2'],
   billingMode: BillingMode.PROVISIONED,
});
XRTable2_lvl2.autoScaleWriteCapacity({
   minCapacity: 1,
   maxCapacity: 10,
}).scaleOnUtilization({ targetUtilizationPercent: 75 });
XRTable2_lvl2.applyRemovalPolicy(RemovalPolicy.RETAIN)

I used the above code to create my global tables. When I deleted the CF stack manually, root table was preserved as per removalpolicy, but all replicas were deleted.

This construct should adhere to dynamodb best practices and create a GlobalTable resource: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/V2globaltables_reqs_bestpractices.html

Reference:

Error message

No response

What is the impact?

If Global tables are created this way, the replica tables retention policy won't be set. This means, the replica tables can be accidentally deleted despite what the code snippet suggests

Workaround

No response

Who is affected?

Anyone creating global tables based on this doc using this library

How do I resolve this?

Customers could use the level 1 CFNGlobalTable constuct as a workaround: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.CfnGlobalTable.html

Related issues

No response

@BalintLab BalintLab added management/tracking Issues that track a subject or multiple issues p0 labels May 25, 2023
@peterwoodworth peterwoodworth changed the title ❗ DynamoDB: Global Table creation doesn't set retention policy for replica tables and doesn't follow DynamoDB best practices DynamoDB: Global Table creation doesn't set retention policy for replica tables and doesn't follow DynamoDB best practices May 25, 2023
@peterwoodworth peterwoodworth changed the title DynamoDB: Global Table creation doesn't set retention policy for replica tables and doesn't follow DynamoDB best practices DynamoDB: Global Table creation doesn't set retention policy for replica tables May 25, 2023
@peterwoodworth peterwoodworth added p1 @aws-cdk/aws-dynamodb Related to Amazon DynamoDB and removed management/tracking Issues that track a subject or multiple issues p0 labels May 25, 2023
@peterwoodworth
Copy link
Contributor

The replicas aren't created through Cfn, so this would need to be handled by the custom resource handler. Could potentially skip deleting some regions here

if (updateTableAction) {
const data = await dynamodb.updateTable({
TableName: tableName,
ReplicaUpdates: [
{
[updateTableAction]: {
RegionName: region,
},
},
],
}).promise();
console.log('Update table: %j', data);
} else {

@peterwoodworth peterwoodworth added the effort/medium Medium work item – several days of effort label May 25, 2023
@BalintLab
Copy link
Author

BalintLab commented May 26, 2023

I'd also recommend creating a global table resource (CfnGlobalTable) when replicaregions is set as per DynamoDB best practices
Also, its not just the retentionpolicy, but any other attribute you set subsequently

@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 21, 2023

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:

@rix0rrr rix0rrr added the ddb-legacy-table This issue has to do with DynamoDB's legacy Table construct. Close after migration guide is out. label Sep 21, 2023
@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 bug This issue is a bug. and removed p1 labels Mar 14, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. ddb-legacy-table This issue has to do with DynamoDB's legacy Table construct. Close after migration guide is out. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants