Commit 353a9bb
authored
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
File tree
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
- integ.dynamodb-v2.cross-account-replica.js.snapshot
- aws-cdk-lib
- aws-dynamodb
- lib
- test
28 files changed
+2972
-11
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 81 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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