mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): report a missing GSI on UpdateTable the way AWS does (#4564)
On AWS, deleting or updating a GSI the table does not have fails with ResourceNotFoundException "Requested resource not found: Index <index> for table <table>", with the table name even when TableName is an ARN. Floci used its own message for a delete and a ValidationException for an update.
This commit is contained in:
1 parent
5e2edcb89b
commit
e7e49f9125
3 files changed
+71
-4
No files matched your search
@@ -2306,8 +2306,7 @@ public class DynamoDbService {
|
||||
|
||||
for (String gsiName : gsiDeletes) {
|
||||
if (table.findGsi(gsiName).isEmpty()) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"Global secondary index " + gsiName + " does not exist on the table", 400);
|
||||
throw missingGsi(gsiName, table.getTableName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4803,6 +4802,11 @@ public class DynamoDbService {
|
||||
}
|
||||
}
|
||||
|
||||
static AwsException missingGsi(String indexName, String tableName) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"Requested resource not found: Index " + indexName + " for table " + tableName, 400);
|
||||
}
|
||||
|
||||
public ImportTableDescription validateImportRequest(JsonNode request) {
|
||||
if (request.path("S3BucketSource").path("S3Bucket").asText("").isBlank()) {
|
||||
throw new AwsException("ValidationException", "S3BucketSource.S3Bucket is required", 400);
|
||||
|
||||
+1
-2
@@ -1728,8 +1728,7 @@ public class NativeDynamoDbJsonHandler {
|
||||
"Cannot delete and update the same index: " + indexName, 400);
|
||||
}
|
||||
if (currentTable.findGsi(indexName).isEmpty()) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The table does not have the specified index: " + indexName, 400);
|
||||
throw DynamoDbService.missingGsi(indexName, currentTable.getTableName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+64
@@ -530,6 +530,70 @@ class DynamoDbIntegrationTest {
|
||||
+ "[PROVISIONED, PAY_PER_REQUEST]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTableOnAMissingGsiReportsResourceNotFound() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "MissingGsiTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "MissingGsiTable",
|
||||
"GlobalSecondaryIndexUpdates": [{"Delete": {"IndexName": "does_not_exist"}}]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo("Requested resource not found: Index does_not_exist for table MissingGsiTable"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "MissingGsiTable",
|
||||
"GlobalSecondaryIndexUpdates": [
|
||||
{"Update": {"IndexName": "does_not_exist", "OnDemandThroughput": {"MaxReadRequestUnits": 10}}}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo("Requested resource not found: Index does_not_exist for table MissingGsiTable"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "MissingGsiTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableWithGsiAndLsi() {
|
||||
given()
|
||||
|
||||
Reference in new issue
Block a user