fix(dynamodb): reject an unknown BillingMode (#4554)

* fix(dynamodb): reject an unknown BillingMode

CreateTable, UpdateTable and ImportTable accepted any BillingMode and
treated an unknown one as PROVISIONED. AWS rejects it with a
ValidationException before looking up the table. ImportTable reports the
member as tableCreationParameters.billingMode.

* fix(dynamodb): check an import's BillingMode before its ClientToken

On AWS an ImportTable retry with the same ClientToken and an unknown
BillingMode fails with the BillingMode ValidationException, not with
ImportConflictException. The check now runs before the token lookup.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-09-28 07:24:11 -04:00
1 parent bf47dd7193
commit b8b5fcd476
4 files changed
+117 -3

No files matched your search

@@ -350,6 +350,51 @@ class DynamoDbImportIntegrationTest {
.body("__type", containsString("ResourceNotFoundException"));
}
@Test
void importTable_invalidBillingMode_returnsValidationException() {
String request = importRequest("ImportBadBilling", BUCKET_NAME, "plain/", "DYNAMODB_JSON", "NONE")
.replace("\"PAY_PER_REQUEST\"", "\"INVALID_MODE\"");
dynamo("ImportTable", request)
.then()
.statusCode(400)
.body("__type", containsString("ValidationException"))
.body("message", equalTo("1 validation error detected: Value 'INVALID_MODE' at "
+ "'tableCreationParameters.billingMode' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]"));
dynamo("DescribeTable", "{\"TableName\": \"ImportBadBilling\"}")
.then()
.statusCode(400)
.body("__type", containsString("ResourceNotFoundException"));
}
@Test
void importTable_invalidBillingModeOnARetry_isAValidationErrorNotAConflict() {
putObject("token-billing/data.json", "{\"Item\":{\"pk\":{\"S\":\"one\"}}}\n");
String body = """
{
"ClientToken": "import-token-billing",
"S3BucketSource": {"S3Bucket": "%s", "S3KeyPrefix": "token-billing/"},
"InputFormat": "DYNAMODB_JSON",
"TableCreationParameters": {
"TableName": "ImportTokenBilling",
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
"BillingMode": "PAY_PER_REQUEST"
}
}
""".formatted(BUCKET_NAME);
dynamo("ImportTable", body).then().statusCode(200);
dynamo("ImportTable", body.replace("\"PAY_PER_REQUEST\"", "\"INVALID_MODE\""))
.then()
.statusCode(400)
.body("__type", containsString("ValidationException"))
.body("message", equalTo("1 validation error detected: Value 'INVALID_MODE' at "
+ "'tableCreationParameters.billingMode' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]"));
}
@Test
void importTable_zstdCompression_returnsValidationException() {
dynamo("ImportTable", importRequest("ImportZstd", BUCKET_NAME, "plain/", "DYNAMODB_JSON", "ZSTD"))
@@ -477,6 +477,59 @@ class DynamoDbIntegrationTest {
.statusCode(200);
}
@Test
void createTableWithInvalidBillingModeFailsValidation() {
given()
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
.contentType(DYNAMODB_CONTENT_TYPE)
.body("""
{
"TableName": "InvalidBillingModeTable",
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
"BillingMode": "INVALID_MODE"
}
""")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("1 validation error detected: Value 'INVALID_MODE' at 'billingMode' "
+ "failed to satisfy constraint: Member must satisfy enum value set: "
+ "[PROVISIONED, PAY_PER_REQUEST]"));
given()
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
.contentType(DYNAMODB_CONTENT_TYPE)
.body("""
{"TableName": "InvalidBillingModeTable"}
""")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
void updateTableWithInvalidBillingModeFailsValidationBeforeTheTableLookup() {
given()
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
.contentType(DYNAMODB_CONTENT_TYPE)
.body("""
{"TableName": "NoSuchBillingModeTable", "BillingMode": "pay_per_request"}
""")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("1 validation error detected: Value 'pay_per_request' at 'billingMode' "
+ "failed to satisfy constraint: Member must satisfy enum value set: "
+ "[PROVISIONED, PAY_PER_REQUEST]"));
}
@Test
void createTableWithGsiAndLsi() {
given()