fix(lambda): honour Publish on CreateFunction and UpdateFunctionCode (#2825)

The Publish flag was never read on either path, so no version was ever
created unless the caller made a separate PublishVersion call, and both
actions reported Version as $LATEST. Terraform reads Version and
qualified_arn straight from that response, so every aws_lambda_function
with publish = true recorded $LATEST — which Lambda@Edge cannot use.

Both actions now publish and report the new version. The ARN they return
differs, following the live service rather than the reference, which does
not distinguish them: CreateFunction keeps the unqualified FunctionArn
while UpdateFunctionCode returns the qualified one, as PublishVersion
does.

Closes #2820
This commit is contained in:
Brian Taylor authored and GitHub committed 2026-08-31 14:52:19 -04:00
1 parent 3aaf74520e
commit a7b2b79492
5 files changed
+304 -1

No files matched your search

@@ -70,8 +70,10 @@ public class LambdaController {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
LambdaFunction fn = lambdaService.createFunction(region, request);
Map<String, Object> configuration = buildFunctionConfiguration(fn);
unqualifyArn(configuration);
return Response.status(201)
.entity(buildFunctionConfiguration(fn))
.entity(configuration)
.build();
} catch (AwsException e) {
throw e;
@@ -585,6 +587,18 @@ public class LambdaController {
return result;
}
/**
* CreateFunction reports the version it published but keeps the unqualified ARN, unlike
* UpdateFunctionCode and PublishVersion which both answer with the qualified form. Measured
* against the live service; the reference does not distinguish them.
*/
private static void unqualifyArn(Map<String, Object> configuration) {
if (configuration.get("FunctionArn") instanceof String arn
&& !"$LATEST".equals(configuration.get("Version"))) {
configuration.put("FunctionArn", arn.substring(0, arn.lastIndexOf(':')));
}
}
private Map<String, Object> buildFunctionConfiguration(LambdaFunction fn) {
ObjectNode node = objectMapper.createObjectNode();
node.put("FunctionName", fn.getFunctionName());
@@ -454,6 +454,9 @@ public class LambdaService implements ResourceProvider {
functionStore.save(region, fn);
LOG.infov("Created Lambda function: {0} in region {1}", functionName, region);
if (Boolean.TRUE.equals(request.get("Publish"))) {
return publishVersion(region, functionName, null);
}
return fn;
}
@@ -530,6 +533,9 @@ public class LambdaService implements ResourceProvider {
functionStore.save(region, fn);
LOG.infov("Updated code for function: {0}", functionName);
if (Boolean.TRUE.equals(request.get("Publish"))) {
return publishVersion(region, functionName, null);
}
return fn;
}