fix(cloudformation): copy a SAM function's VersionDescription to its version (#6770)

With AutoPublishAlias, SAM passes a function's VersionDescription to the
Description of the AWS::Lambda::Version it generates. The transform
dropped it, so a version published from a SAM template never had the
description the template gave it.

The version now takes it as written, leaving an intrinsic function for
CloudFormation to resolve. As in SAM, it stays out of the hash that
names the version, and Globals cannot set it: the transform refuses it
there, as it already refuses AutoPublishCodeSha256.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
This commit is contained in:
Jackson Price authored and GitHub committed 2026-10-27 19:13:02 -04:00
1 parent 1a5decbb4a
commit a6cf29ea86
5 files changed
+343 -10

No files matched your search

@@ -97,11 +97,14 @@ class SamTransformProcessor {
// (including the early return below when Resources is absent or not an object).
JsonNode globals = expanded.path("Globals");
expanded.remove("Globals");
// SAM refuses any Globals property it does not list for a section. AutoPublishCodeSha256 is
// one of them: one value there would name every function's version.
if (globals.path("Function").has("AutoPublishCodeSha256")) {
throw new AwsException("ValidationError", "'Globals' section is invalid. 'AutoPublishCodeSha256' "
+ "is not a supported property of 'Function'.", 400);
// SAM refuses any Globals property it does not list for a section. AutoPublishCodeSha256 and
// VersionDescription are two of them: one value there would name, or describe, every
// function's version.
for (String property : List.of("AutoPublishCodeSha256", "VersionDescription")) {
if (globals.path("Function").has(property)) {
throw new AwsException("ValidationError", "'Globals' section is invalid. '" + property
+ "' is not a supported property of 'Function'.", 400);
}
}
JsonNode resources = expanded.path("Resources");
@@ -1020,6 +1023,7 @@ class SamTransformProcessor {
versionDef.put("Type", "AWS::Lambda::Version");
ObjectNode versionProps = objectMapper.createObjectNode();
versionProps.set("FunctionName", ref(functionLogicalId));
copyRenamed(properties, "VersionDescription", versionProps, "Description");
versionDef.set("Properties", versionProps);
versionDef.setAll(passthrough.deepCopy());
// The version a new hash replaces leaves the template on that update; like SAM, keep it