From a25c0435ee6111a4c8a0f50f7a856ca252af84fa Mon Sep 17 00:00:00 2001 From: Niels Kootstra <545768+nkootstra@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:44:04 +0100 Subject: [PATCH] fix(ec2): list the DynamoDB gateway endpoint service in DescribeVpcEndpointServices (#9016) * fix(ec2): list the DynamoDB gateway endpoint service in DescribeVpcEndpointServices --- docs/configuration/partitions.md | 7 +- docs/services/ec2.md | 2 +- .../aws/services/ec2/Ec2QueryHandler.java | 33 +++++---- .../io/floci/aws/services/ec2/Ec2Service.java | 3 +- ...ynamoDbEndpointServiceIntegrationTest.java | 72 +++++++++++++++++++ ...2VpcEndpointDnsEntriesIntegrationTest.java | 1 + 6 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 src/test/java/io/floci/aws/services/ec2/Ec2DynamoDbEndpointServiceIntegrationTest.java diff --git a/docs/configuration/partitions.md b/docs/configuration/partitions.md index 7165e7e196..5286bfaa2c 100644 --- a/docs/configuration/partitions.md +++ b/docs/configuration/partitions.md @@ -156,9 +156,10 @@ a colon in that setting. Existing stored namespaces are not migrated or deleted are `com.amazonaws..` everywhere, except the (region, service) pairs the CDK lists for China, ISO and EUSC, which reverse the DNS suffix (`cn.com.amazonaws.cn-north-1.lambda`). GovCloud keeps `com.amazonaws`. Gateway endpoints and their AWS-managed prefix lists (S3, - DynamoDB) are `com.amazonaws..` in every partition. S3 offers both kinds: where - the two names agree it is one service carrying both types, and in China it is listed twice, the - gateway `com.amazonaws.cn-north-1.s3` and the interface `cn.com.amazonaws.cn-north-1.s3`. + DynamoDB) are `com.amazonaws..` in every partition. Both offer both kinds: where + the two names agree it is one service carrying both types, and where they differ (S3 in China) it + is listed twice, the gateway `com.amazonaws.cn-north-1.s3` and the interface + `cn.com.amazonaws.cn-north-1.s3`. - **Lambda runtime images** pull from ECR Public (`public.ecr.aws`), which exists only in the commercial partition; point `FLOCI_SERVICES_LAMBDA_ECR_BASE_URI` at a mirror elsewhere. - **WAF `CLOUDFRONT` scope**: available only where CloudFront exists (`aws`, `aws-cn`), and its diff --git a/docs/services/ec2.md b/docs/services/ec2.md index e750712d86..2e81c4bf32 100644 --- a/docs/services/ec2.md +++ b/docs/services/ec2.md @@ -430,7 +430,7 @@ naming different VPCs find nothing. | DescribeDhcpOptions | Lists DHCP options sets by ID or filters, with paginated results. | | AssociateDhcpOptions | Associates an options set with a VPC; `default` leaves the VPC with no DHCP options. | | DeleteDhcpOptions | Deletes an unassociated DHCP options set. | -| DescribeVpcEndpointServices | Lists common AWS interface endpoint services and S3 (gateway and interface) in every availability zone, named per partition (see [Partitions](../configuration/partitions.md)). A `ServiceName` filter is echoed back as asked. | +| DescribeVpcEndpointServices | Lists common AWS interface endpoint services, and S3 and DynamoDB (gateway and interface), in every availability zone, named per partition (see [Partitions](../configuration/partitions.md)). A `ServiceName` filter is echoed back as asked. | | CreateVpcEndpoint | Creates a VPC endpoint record, including its `PolicyDocument` and the per-subnet IPv4 and IPv6 addresses named by `SubnetConfiguration.N`. `IpAddressType` defaults to `ipv4`. Interface and gateway address types are stored as metadata. Synthesized endpoint interfaces still carry IPv4 only; IPv6 networking is not emulated. An `Ipv4` value outside the named subnet's CIDR, or among the first four or the last address AWS reserves in it, is rejected with `InvalidParameterValue`. | | DescribeVpcEndpoints | Lists or returns stored VPC endpoints, including their IP address type. | | ModifyVpcEndpoint | Associates or disassociates route tables, subnets and security groups, sets or resets the endpoint policy, and updates stored `IpAddressType` metadata. Omitting the type preserves its current value; malformed types are rejected before changes are applied. `SubnetConfiguration.N` replaces the addresses pinned for a subnet, under the same address validation as CreateVpcEndpoint. `DnsOptions` is accepted and ignored. | diff --git a/src/main/java/io/floci/aws/services/ec2/Ec2QueryHandler.java b/src/main/java/io/floci/aws/services/ec2/Ec2QueryHandler.java index 54b83f77d2..c0c34a1962 100644 --- a/src/main/java/io/floci/aws/services/ec2/Ec2QueryHandler.java +++ b/src/main/java/io/floci/aws/services/ec2/Ec2QueryHandler.java @@ -1977,6 +1977,9 @@ public class Ec2QueryHandler { "elasticloadbalancing", "sns", "sqs", "kinesis-streams", "kinesis-firehose", "states", "events", "lambda", "glue", "athena", "iot.data", "execute-api"); + // The services AWS also offers as a Gateway endpoint, each named com.amazonaws... + private static final List GATEWAY_ENDPOINT_SERVICES = List.of("s3", "dynamodb"); + private Response handleDescribeVpcEndpointServices(MultivaluedMap p, String region) { List requested = getList(p, "ServiceName"); List>> filters = getFiltersList(p); @@ -2037,10 +2040,13 @@ public class Ec2QueryHandler { private List buildServiceDetails(String region, List requested, List azNames) { List services = new ArrayList<>(); - // S3 is the one service with both offerings. The gateway keeps com.amazonaws in every - // partition; the interface takes the region's prefix, so in China the two are named apart. - String s3Gateway = "com.amazonaws." + region + ".s3"; - String s3Interface = AwsRegionFacts.vpcEndpointServiceName(region, "s3"); + // S3 and DynamoDB are the services with both offerings. The gateway keeps com.amazonaws in + // every partition; the interface takes the region's prefix, so in China S3's two are named apart. + Map gatewayInterfaces = new LinkedHashMap<>(); + for (String name : GATEWAY_ENDPOINT_SERVICES) { + gatewayInterfaces.put("com.amazonaws." + region + "." + name, + AwsRegionFacts.vpcEndpointServiceName(region, name)); + } // Requested service names are echoed verbatim, exactly as AWS does. The emulator // supports any interface service in every AZ, so a requested (often custom) name @@ -2053,22 +2059,23 @@ public class Ec2QueryHandler { for (String name : INTERFACE_ENDPOINT_SERVICES) { fullNames.add(AwsRegionFacts.vpcEndpointServiceName(region, name)); } - fullNames.add(s3Gateway); - if (!s3Interface.equals(s3Gateway)) { - fullNames.add(s3Interface); + for (Map.Entry gateway : gatewayInterfaces.entrySet()) { + fullNames.add(gateway.getKey()); + if (!gateway.getValue().equals(gateway.getKey())) { + fullNames.add(gateway.getValue()); + } } } for (String full : fullNames) { List serviceTypes; - if (full.equals(s3Interface) && !s3Interface.equals(s3Gateway)) { + String gatewayInterface = gatewayInterfaces.get(full); + if (gatewayInterface == null) { serviceTypes = List.of("Interface"); - } else if (full.endsWith(".s3")) { - serviceTypes = s3Interface.equals(s3Gateway) - ? List.of("Gateway", "Interface") - : List.of("Gateway"); + } else if (gatewayInterface.equals(full)) { + serviceTypes = List.of("Gateway", "Interface"); } else { - serviceTypes = List.of("Interface"); + serviceTypes = List.of("Gateway"); } services.add(new ServiceDetail( full, diff --git a/src/main/java/io/floci/aws/services/ec2/Ec2Service.java b/src/main/java/io/floci/aws/services/ec2/Ec2Service.java index e41e0fea32..c9c45a892a 100644 --- a/src/main/java/io/floci/aws/services/ec2/Ec2Service.java +++ b/src/main/java/io/floci/aws/services/ec2/Ec2Service.java @@ -241,7 +241,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab "execute-api", "*.execute-api", "ecs-agent", "ecs-a", "ecs-telemetry", "ecs-t", - "data.iot", ""); + "data.iot", "", + "dynamodb", ""); // A first launch may need to pull a large AMI-backed image. Keep a finite CloudFormation // bound, but allow enough time for that legitimate cold-start path before cancellation. private static final Duration CONTAINER_LAUNCH_TIMEOUT = Duration.ofMinutes(5); diff --git a/src/test/java/io/floci/aws/services/ec2/Ec2DynamoDbEndpointServiceIntegrationTest.java b/src/test/java/io/floci/aws/services/ec2/Ec2DynamoDbEndpointServiceIntegrationTest.java new file mode 100644 index 0000000000..4602198dad --- /dev/null +++ b/src/test/java/io/floci/aws/services/ec2/Ec2DynamoDbEndpointServiceIntegrationTest.java @@ -0,0 +1,72 @@ +package io.floci.aws.services.ec2; + +import io.floci.aws.testing.AwsTestClients; +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.ec2.Ec2Client; +import software.amazon.awssdk.services.ec2.model.DescribeVpcEndpointServicesResponse; +import software.amazon.awssdk.services.ec2.model.Filter; +import software.amazon.awssdk.services.ec2.model.ServiceDetail; +import software.amazon.awssdk.services.ec2.model.ServiceTypeDetail; + +import java.net.URI; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * DynamoDB is, with S3, one of the two services AWS offers as a Gateway endpoint, and it is also + * offered as an Interface endpoint. Terraform's aws_vpc_endpoint_service data source looks the + * service up with a {@code service-name} filter, so it has to be in the default catalog. + */ +@QuarkusTest +class Ec2DynamoDbEndpointServiceIntegrationTest { + + private static final String DYNAMODB = "com.amazonaws.us-east-1.dynamodb"; + + @TestHTTPResource("/") + URI endpoint; + + @Test + void aServiceNameFilterFindsTheDynamoDbGatewayAndInterfaceService() { + try (Ec2Client ec2 = client()) { + DescribeVpcEndpointServicesResponse response = ec2.describeVpcEndpointServices(r -> r.filters( + Filter.builder().name("service-name").values(DYNAMODB).build())); + + assertEquals(List.of(DYNAMODB), response.serviceNames()); + assertEquals(List.of("Gateway", "Interface"), serviceTypes(response.serviceDetails().get(0))); + } + } + + @Test + void aGatewayServiceTypeFilterIncludesDynamoDb() { + try (Ec2Client ec2 = client()) { + DescribeVpcEndpointServicesResponse response = ec2.describeVpcEndpointServices(r -> r.filters( + Filter.builder().name("service-type").values("Gateway").build())); + + assertThat(response.serviceNames(), hasItem(DYNAMODB)); + } + } + + @Test + void aRequestedDynamoDbServiceReportsBothEndpointTypes() { + try (Ec2Client ec2 = client()) { + DescribeVpcEndpointServicesResponse response = + ec2.describeVpcEndpointServices(r -> r.serviceNames(DYNAMODB)); + + assertEquals(List.of("Gateway", "Interface"), serviceTypes(response.serviceDetails().get(0))); + } + } + + private static List serviceTypes(ServiceDetail detail) { + return detail.serviceType().stream().map(ServiceTypeDetail::serviceTypeAsString).toList(); + } + + private Ec2Client client() { + return AwsTestClients.create(Ec2Client.builder(), "000000000000", Region.US_EAST_1, endpoint); + } +} diff --git a/src/test/java/io/floci/aws/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java b/src/test/java/io/floci/aws/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java index 94cc2025a3..02fd3c2e92 100644 --- a/src/test/java/io/floci/aws/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java @@ -158,6 +158,7 @@ class Ec2VpcEndpointDnsEntriesIntegrationTest { Map.entry("glue", "glue"), Map.entry("athena", "athena"), Map.entry("iot.data", ""), + Map.entry("dynamodb", ""), Map.entry("execute-api", "*.execute-api")); static Stream advertisedServicePrivateDnsNames() {