Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(dynamodb): report a missing GSI on UpdateTable the way AWS does (#4564)

TATSUNO “Taz” Yasuhiroe7e49f9125eb
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java
index 49be5401cb..6be8f9c886 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java
@@ -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);
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
index c6dc7f9c0f..b8e693aebb 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
@@ -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());
}
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java
index d8f3345fa4..1686298fc8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java
@@ -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()