fix(apigateway): default a REST custom domain to EDGE when no endpoint type is given (#6885)

* fix(apigateway): default a REST custom domain to EDGE when no endpoint type is given

* docs(apigateway): state the CreateDomainName endpoint type default; cite its source

* test(apigateway): seed the legacy base path mapping test with a REGIONAL domain

The test reads its mappings through the v2 API, which refuses EDGE domains,
and a domain created with no endpoint type now defaults to EDGE.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-28 22:08:18 -04:00
1 parent 4dbe3731a9
commit 043664471b
5 files changed
+59 -5

No files matched your search

+4 -1
View File
@@ -211,7 +211,10 @@ A domain created with `CreateDomainName` is `AVAILABLE` at once. Its `regionalDo
itself is routed through the domain's base path mappings to the mapped REST API stage. An
`EDGE` domain also reports a `distributionDomainName` under `cloudfront.net` and the fixed
CloudFront hosted zone `Z2FDTNDATAQYW2`; a `REGIONAL` domain reports neither, as on AWS. Moving a
domain between the two types with `UpdateDomainName` creates or drops the distribution.
domain between the two types with `UpdateDomainName` creates or drops the distribution. A
domain created with no endpoint type is `EDGE`, as on AWS; it is `REGIONAL` when the request
carries a regional certificate (`regionalCertificateArn` or `regionalCertificateName`) or the
partition has no edge-optimized endpoints.
`GetDomainName` returns the `domainNameArn`, the `endpointConfiguration`, both certificate ARNs
and the `tags`. Tags are managed through `TagResource`, `UntagResource` and `GetTags` on
`arn:aws:apigateway:<region>::/domainnames/<domain>`. A second mapping on a base path that
@@ -2232,6 +2232,17 @@ public class ApiGatewayService implements ResourceProvider {
String domainName = (String) request.get("domainName");
if (domainName == null) throw new AwsException("BadRequestException", "domainName is required", 400);
String endpointType = endpointTypeOf(request);
if (endpointType == null) {
// EDGE is AWS's default for a REST domain: terraform-provider-aws v6.70.0
// internal/service/apigateway/domain_name_test.go (acceptance test against AWS) creates one
// with only certificate_body/certificate_name and asserts a CloudFront domain and zone.
// A regional certificate => REGIONAL is NOT verified against AWS; it keeps Floci's previous
// behaviour, as does REGIONAL in a partition without edge.
boolean regionalCertificate = request.get("regionalCertificateArn") != null
|| request.get("regionalCertificateName") != null;
boolean edgeAvailable = EDGE_OPTIMIZED_PARTITIONS.contains(AwsPartitions.forRegionOrCommercial(region).id());
endpointType = !regionalCertificate && edgeAvailable ? "EDGE" : "REGIONAL";
}
if (!"REGIONAL".equals(endpointType) && !"EDGE".equals(endpointType)) {
// Private custom domains are not emulated; anything else would be a domain that is
// neither regional nor edge-optimized, which nothing here could route or describe.
@@ -2309,8 +2320,7 @@ public class ApiGatewayService implements ResourceProvider {
/**
* Reads the endpoint type from either spelling: REST passes {@code endpointConfiguration.types},
* HTTP APIs pass a single {@code endpointType}. REGIONAL is the default an emulated domain gets,
* since nothing here fronts it with an edge distribution.
* HTTP APIs pass a single {@code endpointType}. Null when the request names neither.
*/
private static String endpointTypeOf(Map<String, Object> request) {
Object endpointType = request.get("endpointType");
@@ -2322,7 +2332,7 @@ public class ApiGatewayService implements ResourceProvider {
&& types.getFirst() instanceof String type && !type.isBlank()) {
return type;
}
return "REGIONAL";
return null;
}
public CustomDomain getDomainName(String region, String domainName) {
@@ -80,6 +80,37 @@ class ApiGatewayDomainNameIntegrationTest {
deleteDomain(domain);
}
@Test
void domainWithOnlyACertificateArnDefaultsToEdge() {
String domain = "default-edge.apigw-domain-it.example.com";
createDomain("""
{"domainName":"%s","certificateArn":"%s"}
""".formatted(domain, CERTIFICATE_ARN));
given().when().get("/domainnames/" + domain).then()
.statusCode(200)
.body("endpointConfiguration.types[0]", equalTo("EDGE"))
.body("distributionDomainName", endsWith(".cloudfront.net"))
.body("distributionHostedZoneId", equalTo("Z2FDTNDATAQYW2"));
deleteDomain(domain);
}
@Test
void domainWithOnlyARegionalCertificateStaysRegional() {
String domain = "default-regional.apigw-domain-it.example.com";
createDomain("""
{"domainName":"%s","regionalCertificateArn":"%s"}
""".formatted(domain, CERTIFICATE_ARN));
given().when().get("/domainnames/" + domain).then()
.statusCode(200)
.body("endpointConfiguration.types[0]", equalTo("REGIONAL"))
.body("distributionDomainName", nullValue());
deleteDomain(domain);
}
@Test
void endpointTypeCanBeMovedFromEdgeToRegional() {
String domain = "endpoint-type.apigw-domain-it.example.com";
@@ -91,4 +91,13 @@ class ApiGatewayEdgeDomainPartitionTest {
assertEquals("BadRequestException", error.getErrorCode());
}
/** Without a type the domain is edge-optimized only where the partition has edge. */
@Test
void aDomainWithoutATypeStaysRegionalWhereThePartitionHasNoCloudFront() {
CustomDomain domain = service.createDomainName(GOV_REGION, Map.of("domainName", "default.example.com",
"certificateArn", "arn:aws-us-gov:acm:us-gov-west-1:000000000000:certificate/d"));
assertEquals("REGIONAL", domain.getEndpointConfigurationType());
}
}
@@ -41,7 +41,8 @@ class LegacyBasePathMappingIntegrationTest {
}
private void seedLegacyState() {
service.createDomainName(REGION, Map.of("domainName", DOMAIN));
// REGIONAL: the v2 mapping API this test reads through refuses an EDGE domain, as AWS does.
service.createDomainName(REGION, Map.of("domainName", DOMAIN, "endpointType", "REGIONAL"));
// The canonical root, as writes produce it today.
service.createBasePathMapping(REGION, DOMAIN, Map.of("restApiId", "api-canonical", "stage", "prod"));
// And one the old write path left under the empty key; its field still reads "(none)".