fix(lambda): support nested python handler module paths (#570)

* fix(lambda): support nested python handler module paths

* fix(lambda): accept python package handlers in zip validation

- close Files.walk with try-with-resources during handler validation
- accept modulePath/__init__.py for python runtimes
- add regression coverage for nested python package handlers

Addresses Copilot feedback on PR #570
This commit is contained in:
Mateus Scheuer Macedo authored and GitHub committed 2026-04-24 20:42:13 -05:00
1 parent 273434893f
commit c687977585
2 files changed
+66 -10

No files matched your search

@@ -1034,16 +1034,22 @@ public class LambdaService {
// For file-based runtimes, verify handler file exists (skip Java and .NET which use different handler formats)
if (fn.getRuntime() != null && !fn.getRuntime().startsWith("java") && !fn.getRuntime().startsWith("dotnet")) {
String handlerFile = fn.getHandler().split("\\.")[0];
boolean found = Files.walk(codePath)
.filter(Files::isRegularFile)
.anyMatch(p -> {
String relative = codePath.relativize(p).toString();
String withoutExt = relative.contains(".")
? relative.substring(0, relative.lastIndexOf('.'))
: relative;
return withoutExt.equals(handlerFile);
});
String handlerFile = resolveHandlerFilePath(fn);
boolean pythonRuntime = fn.getRuntime().startsWith("python");
boolean found;
try (var walk = Files.walk(codePath)) {
found = walk
.filter(Files::isRegularFile)
.anyMatch(p -> {
String relative = codePath.relativize(p).toString();
String withoutExt = relative.contains(".")
? relative.substring(0, relative.lastIndexOf('.'))
: relative;
String normalized = withoutExt.replace('\\', '/');
return normalized.equals(handlerFile)
|| (pythonRuntime && normalized.equals(handlerFile + "/__init__"));
});
}
if (!found) {
throw new AwsException("InvalidParameterValueException",
"Handler file '" + handlerFile + "' not found in deployment package", 400);
@@ -1074,6 +1080,16 @@ public class LambdaService {
extractZipCode(fn, Base64.getEncoder().encodeToString(obj.getData()));
}
private String resolveHandlerFilePath(LambdaFunction fn) {
String handler = fn.getHandler();
int lastDot = handler.lastIndexOf('.');
String modulePath = lastDot >= 0 ? handler.substring(0, lastDot) : handler;
if (fn.getRuntime().startsWith("python")) {
return modulePath.replace('.', '/');
}
return modulePath;
}
// ──────────────────────────── Permissions (Policy) ────────────────────────────
public Map<String, Object> addPermission(String region, String functionName, Map<String, Object> request) {