Skip to content

Commit 353a9bb

Browse files
feat(dynamodb): add cross-account global table replication support (#36895)
### Reason for this change DynamoDB global tables currently only support same-account replication across regions. Customers need the ability to replicate tables across AWS accounts for multi-tenant architectures, organizational boundaries, and disaster recovery scenarios. ### Description of changes Added support for cross-account DynamoDB global table replication through a new TableV2MultiAccountReplica construct and automatic permission management: Core Changes: - Added TableV2MultiAccountReplica construct for creating replicas from source tables in different accounts - Added settingsReplicationMode property to control replication of table settings (indexes, streams, encryption) - Implemented automatic resource policy and KMS permissions for cross-account replication - Added TableGrants class with multiAccountReplicationTo() and multiAccountReplicationFrom() methods Permission Management: - Source table resource policy grants dynamodb:AssociateTableReplica to replica account - Both tables grant DynamoDB replication service read/write permissions with aws:SourceAccount conditions - Automatic KMS key permissions when encryption is enabled Design Decisions: - Used aws:SourceAccount condition instead of aws:SourceArn to avoid circular dependencies - Only pass encryptedResource when encryption key exists to avoid unnecessary policy statements - Validate that source and replica are in different regions - Require explicit table names for cross-account replicas when source uses generated names ### Describe any new or updated permissions being added DynamoDB Table Resource Policies: - dynamodb:AssociateTableReplica - Granted to replica account on source table - dynamodb:ReadDataForReplication, dynamodb:WriteDataForReplication, dynamodb:ReplicateSettings - Granted to replication.dynamodb.amazonaws.com service principal with aws:SourceAccount condition KMS Key Permissions (when encryption enabled): - kms:Decrypt, kms:DescribeKey, kms:Encrypt, kms:ReEncrypt*, kms:GenerateDataKey* - Granted to replication.dynamodb.amazonaws.com service principal ### Description of how you validated changes Unit Tests: - Added tests for TableV2MultiAccountReplica construct - Added tests for cross-account replication permission grants - Added tests for KMS permission grants - Added tests for validation (same-region check, table name requirements) Integration Tests: - Created integ.dynamodb-v2.cross-account-replica.ts - Tests full cross-account replication with both tables in same CDK app - Created integ.dynamodb-v2.cross-account-replica-imported.ts - Tests replication with imported source table from different account - Manually deployed and verified bidirectional replication works with SettingsReplicationMode.ALL ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
1 parent 6c2ea71 commit 353a9bb

28 files changed

+2972
-11
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.cross-account-replica-imported.js.snapshot/ImportedReplicaTestDefaultTestDeployAssert1EFA3D60.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.cross-account-replica-imported.js.snapshot/ImportedReplicaTestDefaultTestDeployAssert1EFA3D60.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.cross-account-replica-imported.js.snapshot/ReplicaStack.assets.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"Resources": {
3+
"ReplicaDDFB2A87": {
4+
"Type": "AWS::DynamoDB::GlobalTable",
5+
"Properties": {
6+
"GlobalTableSourceArn": "arn:aws:dynamodb:eu-west-1:12345678:table/MultiAccountGlobalTable",
7+
"Replicas": [
8+
{
9+
"GlobalTableSettingsReplicationMode": "ENABLED",
10+
"Region": "ca-central-1",
11+
"ResourcePolicy": {
12+
"PolicyDocument": {
13+
"Statement": [
14+
{
15+
"Action": [
16+
"dynamodb:ReadDataForReplication",
17+
"dynamodb:ReplicateSettings",
18+
"dynamodb:WriteDataForReplication"
19+
],
20+
"Condition": {
21+
"StringEquals": {
22+
"aws:SourceAccount": [
23+
"222222222222",
24+
"12345678"
25+
]
26+
}
27+
},
28+
"Effect": "Allow",
29+
"Principal": {
30+
"Service": "replication.dynamodb.amazonaws.com"
31+
},
32+
"Resource": "*",
33+
"Sid": "AllowReplicationService"
34+
}
35+
],
36+
"Version": "2012-10-17"
37+
}
38+
}
39+
}
40+
],
41+
"TableName": "MultiAccountGlobalTable"
42+
},
43+
"UpdateReplacePolicy": "Delete",
44+
"DeletionPolicy": "Delete"
45+
}
46+
},
47+
"Parameters": {
48+
"BootstrapVersion": {
49+
"Type": "AWS::SSM::Parameter::Value<String>",
50+
"Default": "/cdk-bootstrap/hnb659fds/version",
51+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
52+
}
53+
},
54+
"Rules": {
55+
"CheckBootstrapVersion": {
56+
"Assertions": [
57+
{
58+
"Assert": {
59+
"Fn::Not": [
60+
{
61+
"Fn::Contains": [
62+
[
63+
"1",
64+
"2",
65+
"3",
66+
"4",
67+
"5"
68+
],
69+
{
70+
"Ref": "BootstrapVersion"
71+
}
72+
]
73+
}
74+
]
75+
},
76+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
77+
}
78+
]
79+
}
80+
}
81+
}

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.cross-account-replica-imported.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.cross-account-replica-imported.js.snapshot/integ.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)