fix(dynamodb): cap GSI multi-attribute key parts at 4 attributes (#2475)

Closes #2460

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-08-23 16:52:32 -04:00
1 parent 86e1c016cd
commit 13f68670d7
2 files changed
+128

No files matched your search

@@ -88,6 +88,8 @@ public class DynamoDbService {
private final ConcurrentHashMap<String, IdempotencyEntry> txIdempotency = new ConcurrentHashMap<>();
private static final long TX_IDEMPOTENCY_TTL_NANOS = java.time.Duration.ofMinutes(10).toNanos();
private static final int MAX_MULTI_ATTRIBUTE_KEY_PART_SIZE = 4;
private record IdempotencyEntry(String requestHash, long insertedAtNanos) {}
private final RegionResolver regionResolver;
private final ObjectMapper objectMapper;
@@ -314,6 +316,7 @@ public class DynamoDbService {
if (gsis != null && !gsis.isEmpty()) {
for (GlobalSecondaryIndex gsi : gsis) {
validateGsiKeySchemaArity(gsi);
gsi.setIndexArn(table.getTableArn() + "/index/" + gsi.getIndexName());
}
table.setGlobalSecondaryIndexes(new ArrayList<>(gsis));
@@ -344,6 +347,23 @@ public class DynamoDbService {
return table;
}
private void validateGsiKeySchemaArity(GlobalSecondaryIndex gsi) {
long hashCount = gsi.getKeySchema().stream().filter(k -> "HASH".equals(k.getKeyType())).count();
long rangeCount = gsi.getKeySchema().stream().filter(k -> "RANGE".equals(k.getKeyType())).count();
if (hashCount > MAX_MULTI_ATTRIBUTE_KEY_PART_SIZE) {
throw new AwsException("ValidationException",
"One or more parameter values were invalid: Global secondary index "
+ gsi.getIndexName() + " must not have more than "
+ MAX_MULTI_ATTRIBUTE_KEY_PART_SIZE + " partition key (HASH) attributes", 400);
}
if (rangeCount > MAX_MULTI_ATTRIBUTE_KEY_PART_SIZE) {
throw new AwsException("ValidationException",
"One or more parameter values were invalid: Global secondary index "
+ gsi.getIndexName() + " must not have more than "
+ MAX_MULTI_ATTRIBUTE_KEY_PART_SIZE + " sort key (RANGE) attributes", 400);
}
}
public TableDefinition describeTable(String tableName, String region) {
String canonicalTableName = canonicalTableName(region, tableName);
String storageKey = regionKey(region, canonicalTableName);
@@ -1327,6 +1347,7 @@ public class DynamoDbService {
"Attribute: " + k.getAttributeName() + " is not defined in AttributeDefinitions", 400);
}
}
validateGsiKeySchemaArity(newGsi);
}
for (String gsiName : gsiDeletes) {