fix(lambda): answer DeleteFunction of a durable function with 202 (#8271)

DeleteFunction answered 204 for every function. AWS answers 202 with {}
when it deletes a durable function or a published version of one, and
Floci now does the same. A plain function and a missing version still
answer 204.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-14 01:10:32 -04:00
1 parent cb03bc373b
commit ff5b6df114
5 files changed
+83 -8

No files matched your search

+4
View File
@@ -241,6 +241,8 @@ minutes.
The operations under a child context closed without `ReplayChildren=true` are left out of the
invocation event and `GetDurableExecutionState`, as the API reference describes.
`DeleteFunction` of a durable function or one of its versions answers 202.
A callback (`createCallback`, `waitForCallback`) gets a callback id that the
`SendDurableExecutionCallback*` APIs complete. Its `TimeoutSeconds` and `HeartbeatTimeoutSeconds`
fail it with `Callback.Timeout` or `Callback.Heartbeat`, and each heartbeat restarts the heartbeat
@@ -286,6 +288,8 @@ Not emulated yet:
executions.
- The `Lineage` field AWS adds to the trace header.
- The per-execution limits of 3,000 operations and 100 MB of persisted payload.
- The `Deleting` state AWS shows for about a minute after `DeleteFunction` of a durable function.
Floci removes it at once.
## Code signing configuration pagination
@@ -224,7 +224,9 @@ public class LambdaController {
@PathParam("functionName") String functionName,
@QueryParam("Qualifier") String qualifier) {
String region = regionResolver.resolveRegion(headers);
lambdaService.deleteFunction(region, functionName, qualifier);
if (lambdaService.deleteFunction(region, functionName, qualifier)) {
return Response.accepted(objectMapper.createObjectNode()).build();
}
return Response.noContent().build();
}
@@ -1251,13 +1251,15 @@ public class LambdaService implements ResourceProvider {
/**
* DeleteFunction. A Qualifier names a single published version to remove, leaving the
* function and its other versions in place; without one the whole function goes.
* AWS answers 202 for a durable function and keeps it Deleting for about a minute.
*
* @return true when a durable function or an existing version of it was deleted
*/
public void deleteFunction(String region, String functionName, String qualifier) {
public boolean deleteFunction(String region, String functionName, String qualifier) {
if (qualifier != null && !qualifier.isEmpty()) {
deleteFunctionVersion(region, functionName, qualifier);
return;
return deleteFunctionVersion(region, functionName, qualifier);
}
deleteWholeFunction(region, functionName);
return deleteWholeFunction(region, functionName);
}
/**
@@ -1265,7 +1267,7 @@ public class LambdaService implements ResourceProvider {
* {@code $LATEST} or naming an alias is rejected, a version an alias points at is a
* conflict, and a version that does not exist is a silent success rather than a 404.
*/
private void deleteFunctionVersion(String region, String functionName, String qualifier) {
private boolean deleteFunctionVersion(String region, String functionName, String qualifier) {
if (!QUALIFIER.matcher(qualifier).matches()) {
throw SmithyValidationErrors.validationException(
"Value '" + qualifier + "' at 'qualifier' failed"
@@ -1296,7 +1298,7 @@ public class LambdaService implements ResourceProvider {
}
Optional<LambdaFunction> version = functionStore.get(region, name, qualifier);
if (version.isEmpty()) {
return;
return false;
}
synchronized (lockForConcurrencyOp(fn.getFunctionArn())) {
warmPool.deleteProvisionedQualifier(fn, qualifier);
@@ -1308,9 +1310,10 @@ public class LambdaService implements ResourceProvider {
reclaimLegacyCodeDirectoryIfUnused(name);
}
LOG.infov("Deleted version {0} of Lambda function: {1}", qualifier, name);
return fn.isDurable();
}
private void deleteWholeFunction(String region, String functionName) {
private boolean deleteWholeFunction(String region, String functionName) {
LambdaFunction fn = getFunction(region, functionName); // throws 404 if not found
functionName = fn.getFunctionName();
String arn = fn.getFunctionArn();
@@ -1358,6 +1361,7 @@ public class LambdaService implements ResourceProvider {
}
}
LOG.infov("Deleted Lambda function: {0}", functionName);
return fn.isDurable();
}
/**
@@ -253,6 +253,55 @@ class LambdaDurableConfigIntegrationTest {
.body("$", not(hasKey("DurableConfig")));
}
@Test
void deleteFunctionAnswers202ForADurableFunctionAndItsExistingVersion() {
createDurableFunction("durable-delete-fn", "{\"ExecutionTimeout\": 3600}").statusCode(201);
given()
.contentType("application/json")
.body("{}")
.when()
.post(BASE_PATH + "/functions/durable-delete-fn/versions")
.then()
.statusCode(201);
given()
.when()
.delete(BASE_PATH + "/functions/durable-delete-fn?Qualifier=5")
.then()
.statusCode(204)
.body(equalTo(""));
given()
.when()
.delete(BASE_PATH + "/functions/durable-delete-fn?Qualifier=1")
.then()
.statusCode(202)
.contentType("application/json")
.body(equalTo("{}"));
given()
.when()
.delete(BASE_PATH + "/functions/durable-delete-fn")
.then()
.statusCode(202)
.contentType("application/json")
.body(equalTo("{}"));
getConfiguration("durable-delete-fn").statusCode(404);
}
@Test
void deleteFunctionAnswers204ForAPlainFunction() {
createFunction("plain-delete-fn", "").statusCode(201);
given()
.when()
.delete(BASE_PATH + "/functions/plain-delete-fn")
.then()
.statusCode(204)
.body(equalTo(""));
}
private static ValidatableResponse updateDurableConfig(String name, String durableConfig) {
return updateConfiguration(name, "{\"DurableConfig\": " + durableConfig + "}");
}
@@ -645,6 +645,22 @@ class LambdaServiceTest {
assertThrows(AwsException.class, () -> service.getFunction(REGION, "del-fn"));
}
@Test
void deleteFunctionReportsWhetherADurableFunctionOrItsVersionWasDeleted() {
Map<String, Object> durable = baseRequest("del-durable-fn");
durable.put("DurableConfig", Map.of("ExecutionTimeout", 3600));
service.createFunction(REGION, durable);
service.publishVersion(REGION, "del-durable-fn", null);
service.createFunction(REGION, baseRequest("del-plain-fn"));
service.publishVersion(REGION, "del-plain-fn", null);
assertFalse(service.deleteFunction(REGION, "del-durable-fn", "5"));
assertTrue(service.deleteFunction(REGION, "del-durable-fn", "1"));
assertTrue(service.deleteFunction(REGION, "del-durable-fn", null));
assertFalse(service.deleteFunction(REGION, "del-plain-fn", "1"));
assertFalse(service.deleteFunction(REGION, "del-plain-fn", null));
}
@Test
void deleteFunctionThrows404WhenNotFound() {
AwsException ex = assertThrows(AwsException.class,