feat(ec2): DescribeVpcEndpointServices returns the common interface services with AZs (#2007)

* feat(ec2): DescribeVpcEndpointServices returns the common interface services with AZs

The empty service set aborted CDK InterfaceVpcEndpoint synthesis
(lookupSupportedAzs calls this at synth time). Now returns the standard
com.amazonaws.<region>.<service> interface services (ec2, ssm, logs,
sts, secretsmanager, kms, ecr, ecs, lambda, iot.data, ...) plus s3, each
with the region's AZs and serviceType, honoring a ServiceName filter.

Fixes #2004

* fix(ec2): DescribeVpcEndpointServices echoes an explicit ServiceName with all AZs

An explicit ServiceName filter (CDK InterfaceVpcEndpoint queries a
specific, often custom, service name) now returns exactly that service in
every AZ, instead of an empty AZ set when the name isn't in the built-in
list — which failed synth with 'lookupSupportedAzs returned <> but
subnets have AZs ...'.

* test(ec2): pin the s3-Gateway and ecr.api-Interface pairing in the endpoint-services test

* fix(ec2): report both endpoint types for S3 and update the SDK compatibility test

Two gaps flagged in review.

S3 is the one service with both a Gateway and an Interface offering, and AWS
reports both on its single service detail. The handler emitted Gateway only,
despite the comment above the loop saying otherwise, so an interface-endpoint
lookup for S3 found nothing.

The Java SDK compatibility suite still asserted that serviceNames and
serviceDetails come back empty, which the populated response violates. It now
asserts what the endpoint actually returns: the S3 detail carrying both types,
an interface-only service, and non-empty availability zones.
This commit is contained in:
lex00 authored and GitHub committed 2026-08-14 22:59:47 -04:00
1 parent 4058dfae00
commit 42a79a7fd7
3 files changed
+109 -8

No files matched your search

@@ -697,13 +697,29 @@ class Ec2Tests {
@Test
@Order(49)
@DisplayName("DescribeVpcEndpointServices - returns empty list")
@DisplayName("DescribeVpcEndpointServices - lists the common services with AZs")
void describeVpcEndpointServices() {
DescribeVpcEndpointServicesResponse resp = ec2.describeVpcEndpointServices(
DescribeVpcEndpointServicesRequest.builder().build());
assertThat(resp.serviceNames()).isEmpty();
assertThat(resp.serviceDetails()).isEmpty();
assertThat(resp.serviceNames()).contains("com.amazonaws.us-east-1.s3");
assertThat(resp.serviceDetails()).isNotEmpty();
ServiceDetail s3 = resp.serviceDetails().stream()
.filter(d -> d.serviceName().equals("com.amazonaws.us-east-1.s3"))
.findFirst()
.orElseThrow();
// S3 is the one service offering both endpoint types.
assertThat(s3.serviceType().stream().map(ServiceTypeDetail::serviceTypeAsString).toList())
.containsExactlyInAnyOrder("Gateway", "Interface");
assertThat(s3.availabilityZones()).isNotEmpty();
ServiceDetail ecr = resp.serviceDetails().stream()
.filter(d -> d.serviceName().equals("com.amazonaws.us-east-1.ecr.api"))
.findFirst()
.orElseThrow();
assertThat(ecr.serviceType().stream().map(ServiceTypeDetail::serviceTypeAsString).toList())
.containsExactly("Interface");
}
@Test
@@ -891,15 +891,64 @@ public class Ec2QueryHandler {
return xmlResponse(xml.build());
}
// The common AWS interface-endpoint services, as short names. Rendered as
// com.amazonaws.<region>.<name>. CDK's InterfaceVpcEndpoint (lookupSupportedAzs)
// calls DescribeVpcEndpointServices at synth time; an empty set aborts synth.
private static final List<String> INTERFACE_ENDPOINT_SERVICES = List.of(
"ec2", "ec2messages", "ssm", "ssmmessages", "logs", "monitoring", "sts",
"secretsmanager", "kms", "ecr.api", "ecr.dkr", "ecs", "ecs-agent", "ecs-telemetry",
"elasticloadbalancing", "sns", "sqs", "kinesis-streams", "kinesis-firehose",
"states", "events", "lambda", "glue", "athena", "iot.data", "execute-api");
private Response handleDescribeVpcEndpointServices(MultivaluedMap<String, String> p, String region) {
List<String> requested = getList(p, "ServiceName");
List<String> azNames = service.describeAvailabilityZones(region).stream()
.map(z -> z.get("zoneName")).toList();
XmlBuilder xml = new XmlBuilder()
.start("DescribeVpcEndpointServicesResponse", AwsNamespaces.EC2)
.elem("requestId", UUID.randomUUID().toString())
.start("serviceNameSet")
.end("serviceNameSet")
.start("serviceDetailSet")
.end("serviceDetailSet")
.end("DescribeVpcEndpointServicesResponse");
.start("serviceNameSet");
List<String> fullNames = new ArrayList<>();
// An explicit ServiceName filter wins: the emulator supports any
// interface service in every AZ, so echo exactly what was asked. CDK's
// InterfaceVpcEndpoint queries a specific (often custom) service name
// and fails if the response omits it or lists no AZs.
if (!requested.isEmpty()) {
fullNames.addAll(requested);
} else {
// S3 has both a Gateway and an Interface offering; keep it in the set.
for (String name : INTERFACE_ENDPOINT_SERVICES) {
fullNames.add("com.amazonaws." + region + "." + name);
}
fullNames.add("com.amazonaws." + region + ".s3");
}
for (String full : fullNames) {
xml.elem("item", full);
}
xml.end("serviceNameSet").start("serviceDetailSet");
for (String full : fullNames) {
// S3 is the one service with both offerings, and AWS reports both
// types on its single service detail. Everything else is Interface.
List<String> serviceTypes = full.endsWith(".s3")
? List.of("Gateway", "Interface")
: List.of("Interface");
xml.start("item")
.elem("serviceName", full)
.start("serviceType");
for (String serviceType : serviceTypes) {
xml.start("item").elem("serviceType", serviceType).end("item");
}
xml.end("serviceType")
.start("availabilityZoneSet");
for (String az : azNames) xml.elem("item", az);
xml.end("availabilityZoneSet")
.elem("owner", "amazon")
.elem("acceptanceRequired", "false")
.elem("managesVpcEndpoints", "false")
.end("item");
}
xml.end("serviceDetailSet").end("DescribeVpcEndpointServicesResponse");
return xmlResponse(xml.build());
}
@@ -1479,6 +1479,42 @@ class Ec2IntegrationTest {
.body(not(containsString("UnsupportedOperation")));
}
@Test
@Order(52)
void describeVpcEndpointServicesEchoesAnExplicitServiceNameWithAzs() {
given()
.formParam("Action", "DescribeVpcEndpointServices")
.formParam("ServiceName.1", "com.amazonaws.us-east-1.custom-iot-data")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("custom-iot-data"))
.body(containsString("us-east-1a"));
}
@Test
@Order(52)
void describeVpcEndpointServicesListsInterfaceServicesWithAzs() {
given()
.formParam("Action", "DescribeVpcEndpointServices")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString(
"<serviceName>com.amazonaws.us-east-1.ecr.api</serviceName><serviceType><item><serviceType>Interface</serviceType>"))
// S3 carries both offerings, in that order.
.body(containsString(
"<serviceName>com.amazonaws.us-east-1.s3</serviceName><serviceType>"
+ "<item><serviceType>Gateway</serviceType></item>"
+ "<item><serviceType>Interface</serviceType></item>"
+ "</serviceType>"))
.body(containsString("us-east-1a"));
}
@Test
@Order(52)
void describeInternetGateways() {