From 60252c9b7f36d13dbf9b091d0b026a2a5dbf3d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Thu, 12 Nov 2026 22:10:59 +0900 Subject: [PATCH] feat(dynamodb): serve DescribeLimits and DescribeEndpoints (#8099) * feat(dynamodb): serve DescribeLimits and DescribeEndpoints DynamoDB reports the default quotas of 80,000 read and write capacity units per account and 40,000 per table. It names its Regional endpoint with a cache period of 1,440 minutes. * fix(dynamodb): name Floci's own address in DescribeEndpoints With endpoint discovery on, the AWS SDK for Java 2.x sends later requests to the address DescribeEndpoints names, even when the client sets an endpoint. The Regional AWS host sent them to real DynamoDB. --- docs/services/dynamodb.md | 2 ++ .../dynamodb/NativeDynamoDbJsonHandler.java | 33 +++++++++++++++++-- .../dynamodb/DynamoDbIntegrationTest.java | 30 +++++++++++++++++ .../backend/DynamoDbNativeBackendTest.java | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/services/dynamodb.md b/docs/services/dynamodb.md index 496311707a..8206ace71b 100644 --- a/docs/services/dynamodb.md +++ b/docs/services/dynamodb.md @@ -26,6 +26,8 @@ including batch, transaction and PartiQL table extraction. | `DeleteTable` | Delete a table | | `DescribeTable` | Get table metadata | | `ListTables` | List all tables | +| `DescribeLimits` | Get the default account and table capacity quotas | +| `DescribeEndpoints` | Get Floci's own host and port as the endpoint | | `UpdateTable` | Update throughput, indexes, streams | | `PutItem` | Write an item | | `GetItem` | Read an item by primary key | diff --git a/src/main/java/io/floci/aws/services/dynamodb/NativeDynamoDbJsonHandler.java b/src/main/java/io/floci/aws/services/dynamodb/NativeDynamoDbJsonHandler.java index c76f902660..7f0ac440ad 100644 --- a/src/main/java/io/floci/aws/services/dynamodb/NativeDynamoDbJsonHandler.java +++ b/src/main/java/io/floci/aws/services/dynamodb/NativeDynamoDbJsonHandler.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import io.floci.aws.config.EmulatorConfig; import io.floci.aws.core.common.AwsArnUtils; import io.floci.aws.core.common.AwsErrorResponse; import io.floci.aws.core.common.AwsException; @@ -37,6 +38,7 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.core.Response; +import java.net.URI; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -87,15 +89,17 @@ public class NativeDynamoDbJsonHandler { private final DynamoDbService dynamoDbService; private final NativeDynamoDbTableService tableService; private final ObjectMapper objectMapper; + private final EmulatorConfig config; private final DynamoDbPartiQLHandler partiQLHandler; private final Object importLock = new Object(); @Inject public NativeDynamoDbJsonHandler(DynamoDbService dynamoDbService, NativeDynamoDbTableService tableService, - ObjectMapper objectMapper) { + ObjectMapper objectMapper, EmulatorConfig config) { this.dynamoDbService = dynamoDbService; this.tableService = tableService; this.objectMapper = objectMapper; + this.config = config; this.partiQLHandler = new DynamoDbPartiQLHandler(dynamoDbService, objectMapper); } @@ -103,7 +107,7 @@ public class NativeDynamoDbJsonHandler { NativeDynamoDbJsonHandler(DynamoDbService dynamoDbService, DynamoDbStreamService dynamoDbStreamService, KinesisService kinesisService, ObjectMapper objectMapper) { this(dynamoDbService, new NativeDynamoDbTableService(dynamoDbService, dynamoDbStreamService, kinesisService), - objectMapper); + objectMapper, null); } public Response handle(String action, JsonNode request, String region) throws Exception { @@ -112,6 +116,8 @@ public class NativeDynamoDbJsonHandler { case "DeleteTable" -> handleDeleteTable(request, region); case "DescribeTable" -> handleDescribeTable(request, region); case "ListTables" -> handleListTables(request, region); + case "DescribeLimits" -> handleDescribeLimits(); + case "DescribeEndpoints" -> handleDescribeEndpoints(); case "PutItem" -> handlePutItem(request, region); case "GetItem" -> handleGetItem(request, region); case "DeleteItem" -> handleDeleteItem(request, region); @@ -166,6 +172,29 @@ public class NativeDynamoDbJsonHandler { }; } + // The default account quotas, the same in every Region measured. + private static final long ACCOUNT_MAX_CAPACITY_UNITS = 80_000; + private static final long TABLE_MAX_CAPACITY_UNITS = 40_000; + private static final int ENDPOINT_CACHE_PERIOD_IN_MINUTES = 1440; + + private Response handleDescribeLimits() { + ObjectNode response = objectMapper.createObjectNode(); + response.put("AccountMaxReadCapacityUnits", ACCOUNT_MAX_CAPACITY_UNITS); + response.put("AccountMaxWriteCapacityUnits", ACCOUNT_MAX_CAPACITY_UNITS); + response.put("TableMaxReadCapacityUnits", TABLE_MAX_CAPACITY_UNITS); + response.put("TableMaxWriteCapacityUnits", TABLE_MAX_CAPACITY_UNITS); + return Response.ok(response).build(); + } + + // A client with endpoint discovery on sends its later requests to this address, so it names Floci. + private Response handleDescribeEndpoints() { + ObjectNode response = objectMapper.createObjectNode(); + response.putArray("Endpoints").addObject() + .put("Address", URI.create(config.effectiveBaseUrl()).getAuthority()) + .put("CachePeriodInMinutes", ENDPOINT_CACHE_PERIOD_IN_MINUTES); + return Response.ok(response).build(); + } + private Response handleCreateTable(JsonNode request, String region) { DynamoDbTableNames.requireShortName(textOrNull(request, "TableName")); throwValidationErrors(createTableViolations(request)); diff --git a/src/test/java/io/floci/aws/services/dynamodb/DynamoDbIntegrationTest.java b/src/test/java/io/floci/aws/services/dynamodb/DynamoDbIntegrationTest.java index 21dce5488b..c5e2313864 100644 --- a/src/test/java/io/floci/aws/services/dynamodb/DynamoDbIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/dynamodb/DynamoDbIntegrationTest.java @@ -878,6 +878,36 @@ class DynamoDbIntegrationTest { .body("TableNames", hasItem("TestTable")); } + @Test + void describeLimitsReportsTheDefaultQuotas() { + given() + .header("X-Amz-Target", "DynamoDB_20120810.DescribeLimits") + .contentType(DYNAMODB_CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("AccountMaxReadCapacityUnits", equalTo(80000)) + .body("AccountMaxWriteCapacityUnits", equalTo(80000)) + .body("TableMaxReadCapacityUnits", equalTo(40000)) + .body("TableMaxWriteCapacityUnits", equalTo(40000)); + } + + @Test + void describeEndpointsNamesFloci() { + given() + .header("X-Amz-Target", "DynamoDB_20120810.DescribeEndpoints") + .contentType(DYNAMODB_CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("Endpoints.Address", contains("localhost:4566")) + .body("Endpoints.CachePeriodInMinutes", contains(1440)); + } + @Test @Order(5) void putItem() { diff --git a/src/test/java/io/floci/aws/services/dynamodb/backend/DynamoDbNativeBackendTest.java b/src/test/java/io/floci/aws/services/dynamodb/backend/DynamoDbNativeBackendTest.java index 071b77fc3e..bd05d45ea8 100644 --- a/src/test/java/io/floci/aws/services/dynamodb/backend/DynamoDbNativeBackendTest.java +++ b/src/test/java/io/floci/aws/services/dynamodb/backend/DynamoDbNativeBackendTest.java @@ -74,7 +74,7 @@ class DynamoDbNativeBackendTest { DynamoDbService service = new DynamoDbService(storageFactory, new RegionResolver(REGION, ACCOUNT), streams, forwarder, null, mapper, mock(EmulatorConfig.class, RETURNS_DEEP_STUBS)); NativeDynamoDbTableService tables = new NativeDynamoDbTableService(service, streams, mock(KinesisService.class)); - backend = new NativeDynamoDbBackend(new NativeDynamoDbJsonHandler(service, tables, mapper), + backend = new NativeDynamoDbBackend(new NativeDynamoDbJsonHandler(service, tables, mapper, mock(EmulatorConfig.class)), new NativeDynamoDbStreamsJsonHandler(streams, service, new RegionResolver(REGION, ACCOUNT), mapper), tables, service, streams, ttl, mapper); }