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.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-12 09:10:59 -04:00
1 parent 59c2b46e1c
commit 60252c9b7f
4 files changed
+64 -3

No files matched your search

+2
View File
@@ -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 |
@@ -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));
@@ -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() {
@@ -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);
}