Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ec2): DescribeVpcEndpointServices returns the common interface services with AZs (#2007)
lex0042a79a7fd71f
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.javaindex 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");}@Testdiff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.javaindex 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.<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());}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.javaindex 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(+ "<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() {