fix(dynamodb): report a global table's home region as a replica in DescribeTable (#4197)

On AWS a global table (version 2019.11.21) has no primary: the region it was
created in is one of its replicas, and DescribeTable lists it under Replicas
as ACTIVE next to the others. The CDK's TableV2 calls that table the default
replica and refuses a declared replica in the primary table's region
(aws-dynamodb/lib/table-v2.ts:280,394), which is why the CloudFormation
provisioner filters the deployment region out of its ReplicaUpdates reconcile.
Floci only knew the other regions, so a single-region
AWS::DynamoDB::GlobalTable described with no replicas and a two-region one
listed only the second.

TableDefinition.globalTableHomeRegion records the creating region once a
replica is added (UpdateTable ReplicaUpdates, Custom::DynamoDBReplica) or when
the GlobalTable provisioner calls the new idempotent ensureGlobalTable, and
DescribeTable appends it as an ACTIVE replica after the tracked ones with
GlobalTableVersion. A plain table has no home region and reports neither.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-22 22:23:31 -04:00
1 parent a459dedd43
commit d96e41cf2f
6 files changed
+76 -11

No files matched your search

@@ -89,14 +89,14 @@ class CloudFormationDynamoDbGlobalTableIntegrationTest {
assertTrue(tableArn != null && tableArn.startsWith("arn:aws:dynamodb:"), "TableArn: " + tableArn);
assertFalse(tableId == null || tableId.isBlank(), "DescribeTable reported no TableId");
// The Replicas property is applied: the non-local region is tracked and surfaced by
// DescribeTable. Whether the deployment region itself appears in Replicas is deliberately not
// asserted here: on AWS a global table lists its stack region as a replica too, and reporting
// that is a DescribeTable follow-up (the reconcile must keep filtering the local region, since
// the UpdateTable ReplicaUpdates API rejects adding it).
// The Replicas property is applied: the declared non-local region is tracked, and the
// deployment region is reported as a replica too, so DescribeTable lists both, as AWS does for
// a global table.
List<String> replicaRegions = described.getList("Table.Replicas.RegionName");
assertTrue(replicaRegions != null && replicaRegions.contains("us-west-2"),
"DescribeTable Replicas did not report us-west-2: " + replicaRegions);
assertTrue(replicaRegions.contains("us-east-1"),
"DescribeTable Replicas did not report the deployment region us-east-1: " + replicaRegions);
assertEquals(tableName, parameterValue("/gt-v2/" + suffix + "/ref"));
assertEquals(tableArn, parameterValue("/gt-v2/" + suffix + "/arn"));
@@ -435,6 +435,30 @@ class DynamoDbServiceTest {
assertTrue(service.describeTable("Users", "us-east-1").getReplicaRegions().isEmpty());
}
@Test
void addingAReplicaMarksTheTableGlobalHomedInTheUpdateRegion() {
createUsersTable("us-east-1");
assertNull(service.describeTable("Users", "us-east-1").getGlobalTableHomeRegion());
service.applyReplicaUpdates("Users", List.of("eu-west-1"), List.of(), "us-east-1");
assertEquals("us-east-1", service.describeTable("Users", "us-east-1").getGlobalTableHomeRegion());
// The home region stays a global table even after the last replica is removed.
service.applyReplicaUpdates("Users", List.of(), List.of("eu-west-1"), "us-east-1");
assertEquals("us-east-1", service.describeTable("Users", "us-east-1").getGlobalTableHomeRegion());
}
@Test
void ensureGlobalTableMarksTheHomeRegionAndIsIdempotent() {
createUsersTable("us-east-1");
service.ensureGlobalTable("Users", "us-east-1");
service.ensureGlobalTable("Users", "us-east-1");
assertEquals("us-east-1", service.describeTable("Users", "us-east-1").getGlobalTableHomeRegion());
assertTrue(service.describeTable("Users", "us-east-1").getReplicaRegions().isEmpty());
}
@Test
void invalidReplicaUpdateLeavesExistingReplicasUnchanged() {
createUsersTable("us-east-1");