From 42a79a7fd71f4f72c6eb37cfd851b4ff5acb712a Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Fri, 14 Aug 2026 20:59:47 -0600 Subject: [PATCH] feat(ec2): DescribeVpcEndpointServices returns the common interface services with AZs (#2007) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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.. 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. --- .../test/java/com/floci/test/Ec2Tests.java | 22 ++++++- .../floci/services/ec2/Ec2QueryHandler.java | 59 +++++++++++++++++-- .../services/ec2/Ec2IntegrationTest.java | 36 +++++++++++ 3 files changed, 109 insertions(+), 8 deletions(-) diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java index 623482f4df..9f96c1a8e1 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java @@ -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 diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java index 8a7009c6f6..52e1e1f530 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java @@ -891,15 +891,64 @@ public class Ec2QueryHandler { return xmlResponse(xml.build()); } + // The common AWS interface-endpoint services, as short names. Rendered as + // com.amazonaws... CDK's InterfaceVpcEndpoint (lookupSupportedAzs) + // calls DescribeVpcEndpointServices at synth time; an empty set aborts synth. + private static final List 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 p, String region) { + List requested = getList(p, "ServiceName"); + List 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 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 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()); } diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java index 8de108f85f..9d3f5087be 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java @@ -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( + "com.amazonaws.us-east-1.ecr.apiInterface")) + // S3 carries both offerings, in that order. + .body(containsString( + "com.amazonaws.us-east-1.s3" + + "Gateway" + + "Interface" + + "")) + .body(containsString("us-east-1a")); + } + @Test @Order(52) void describeInternetGateways() {