fix(lambda): check RevisionId before applying UpdateFunctionConfiguration changes (#4637)

* fix(lambda): check RevisionId before applying UpdateFunctionConfiguration changes

A stale RevisionId returned 412 but left the rejected fields on the live stored function; the precondition now runs before any mutation.

Fixes #4605

* fix(lambda): validate fields before checking RevisionId in UpdateFunctionConfiguration
This commit is contained in:
Sam Fakhreddine authored and GitHub committed 2026-10-05 21:56:08 -04:00
1 parent fa1268bcbb
commit d4b7265b49
2 files changed
+48 -11

No files matched your search

@@ -863,6 +863,17 @@ public class LambdaService implements ResourceProvider {
validateFileSystemVpcConfig(requestedFileSystemConfigs, requestedVpcConfig);
}
// RevisionId optimistic locking runs after request validation, like AWS, and before any field mutation
if (request.containsKey("RevisionId")) {
String incomingRevision = (String) request.get("RevisionId");
if (incomingRevision != null && !incomingRevision.equals(fn.getRevisionId())) {
throw new AwsException("PreconditionFailedException",
"The Revision Id provided does not match the latest Revision Id. "
+ "Call the GetFunction or the GetFunctionConfiguration API to retrieve "
+ "the latest Revision Id for your resource.", 412);
}
}
if (request.containsKey("Description")) {
fn.setDescription((String) request.get("Description"));
}
@@ -887,17 +898,6 @@ public class LambdaService implements ResourceProvider {
}
}
// RevisionId optimistic locking
if (request.containsKey("RevisionId")) {
String incomingRevision = (String) request.get("RevisionId");
if (incomingRevision != null && !incomingRevision.equals(fn.getRevisionId())) {
throw new AwsException("PreconditionFailedException",
"The Revision Id provided does not match the latest Revision Id. "
+ "Call the GetFunction or the GetFunctionConfiguration API to retrieve "
+ "the latest Revision Id for your resource.", 412);
}
}
if (architectures != null) {
fn.setArchitectures(new ArrayList<>(architectures));
}
@@ -2286,4 +2286,41 @@ class LambdaServiceTest {
assertEquals("ResourceNotFoundException",
assertThrows(AwsException.class, () -> service.getFunction(REGION, "package-type-fn")).getErrorCode());
}
@Test
void updateFunctionConfigurationWithStaleRevisionIdRollsBack() {
// Catches: stale RevisionId rejection leaves rejected changes (Timeout) visible afterwards
Map<String, Object> request = baseRequest("rollback-test-function");
LambdaFunction fn = service.createFunction(REGION, request);
String originalRevisionId = fn.getRevisionId();
Map<String, Object> updateRequest = Map.of(
"RevisionId", "stale-id",
"Timeout", 99);
AwsException thrown = assertThrows(AwsException.class, () -> {
service.updateFunctionConfiguration(REGION, "rollback-test-function", updateRequest);
});
assertEquals("PreconditionFailedException", thrown.getErrorCode());
assertEquals(412, thrown.getHttpStatus());
LambdaFunction updatedFn = service.getFunction(REGION, "rollback-test-function");
assertEquals(originalRevisionId, updatedFn.getRevisionId());
assertEquals(10, updatedFn.getTimeout());
}
@Test
void updateFunctionConfigurationValidatesFieldsBeforeCheckingRevisionId() {
// Catches: a stale RevisionId answers 412 ahead of the ValidationException an over-long Description earns
service.createFunction(REGION, baseRequest("validation-order-function"));
Map<String, Object> updateRequest = Map.of(
"RevisionId", "stale-id",
"Description", "d".repeat(300));
AwsException thrown = assertThrows(AwsException.class,
() -> service.updateFunctionConfiguration(REGION, "validation-order-function", updateRequest));
assertEquals("ValidationException", thrown.getErrorCode());
assertEquals(400, thrown.getHttpStatus());
}
}