fix(cognito): name a custom domain's CloudFront distribution like the others (#7486)

CreateUserPoolDomain built its CloudFrontDistribution by hand from 14 hex
characters with no leading d, unlike the names an edge-optimized API Gateway
domain and an AppSync custom domain get. Use CloudFrontEdgeDomain.create, so
the name is d plus 13 hex on the partition's suffix. The name is stored, so
existing domains keep theirs.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-04 05:17:53 -04:00
1 parent e46579ec03
commit 86f8434ef6
2 files changed
+16 -7

No files matched your search

@@ -14,6 +14,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -103,6 +104,7 @@ class CognitoCustomDomainPartitionTest {
UserPoolDomain created = service.createUserPoolDomain(CUSTOM_DOMAIN, poolId, CUSTOM, null);
assertTrue(created.isCustomDomain());
assertThat(created.getCloudFrontDistribution(), matchesPattern("d[0-9a-f]{13}\\.cloudfront\\.net"));
Map<String, Object> replacement =
Map.of("CertificateArn", "arn:aws:acm:us-east-1:" + ACCOUNT + ":certificate/def");
@@ -110,6 +112,18 @@ class CognitoCustomDomainPartitionTest {
assertEquals(replacement.get("CertificateArn"), updated.getCertificateArn());
}
@Test
void aCustomDomainInChinaIsServedFromTheChinaCloudFrontSuffix() {
CognitoService service = serviceIn("cn-north-1");
String poolId = createPool(service, "cn-north-1");
Map<String, Object> certificate =
Map.of("CertificateArn", "arn:aws-cn:acm:us-east-1:" + ACCOUNT + ":certificate/abc");
UserPoolDomain created = service.createUserPoolDomain(CUSTOM_DOMAIN, poolId, certificate, null);
assertThat(created.getCloudFrontDistribution(), matchesPattern("d[0-9a-f]{13}\\.cloudfront\\.cn"));
}
@ParameterizedTest
@ValueSource(strings = {
"arn:aws-cn:acm:us-east-1:000000000000:certificate/abc",