fix(cloudformation): wrap ZipFile inline source in zip archive before passing to Lambda (#639)

CloudFormation's ZipFile property contains raw source code (JS, Python, etc.),
but LambdaService expects Code.ZipFile to be a base64-encoded zip archive per
the Lambda REST API contract. Passing raw source directly caused every inline
Lambda to land in CREATE_FAILED with "Illegal base64 character".

Fix: added sourceToZipBase64() that wraps the raw source in a ZipEntry (filename
derived from the Handler property and runtime extension — .js for Node, .py for
Python) and base64-encodes the archive before forwarding to LambdaService.

Closes #607
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-04-28 22:36:30 -05:00
1 parent 77db7d24ef
commit 87eda4bcfc
3 files changed
+240 -1

No files matched your search

@@ -409,7 +409,9 @@ public class CloudFormationResourceProvisioner {
String zipFile = codeNode.path("ZipFile").asText(null);
if (zipFile != null) {
return Map.of("ZipFile", zipFile);
String handler = resolveOrDefault(props, "Handler", engine, "index.handler");
String runtime = resolveOrDefault(props, "Runtime", engine, "nodejs18.x");
return Map.of("ZipFile", sourceToZipBase64(zipFile, handler, runtime));
}
String imageUri = codeNode.path("ImageUri").asText(null);
@@ -420,6 +422,22 @@ public class CloudFormationResourceProvisioner {
return Map.of("ZipFile", defaultHandlerZipBase64());
}
private static String sourceToZipBase64(String source, String handler, String runtime) {
String module = handler.contains(".") ? handler.substring(0, handler.lastIndexOf('.')) : "index";
String ext = runtime.startsWith("python") ? ".py" : ".js";
try {
var baos = new ByteArrayOutputStream();
try (var zos = new ZipOutputStream(baos)) {
zos.putNextEntry(new ZipEntry(module + ext));
zos.write(source.getBytes(StandardCharsets.UTF_8));
zos.closeEntry();
}
return Base64.getEncoder().encodeToString(baos.toByteArray());
} catch (Exception e) {
throw new RuntimeException("Failed to create zip from ZipFile source", e);
}
}
private static String defaultHandlerZipBase64() {
try {
var baos = new ByteArrayOutputStream();