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

@@ -264,6 +264,32 @@ class LambdaServiceTest {
assertEquals("index.handler", fn.getHandler());
}
@Test
void createFunctionWithNestedPythonModuleHandler() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(
"FunctionName", "nested-python-handler-fn",
"Runtime", "python3.11",
"Role", "arn:aws:iam::000000000000:role/test-role",
"Handler", "apps.foo.src.lambda_handler.lambda_handler",
"Code", Map.of("ZipFile", createZipBase64("apps/foo/src/lambda_handler.py"))
));
LambdaFunction fn = service.createFunction(REGION, req);
assertEquals("apps.foo.src.lambda_handler.lambda_handler", fn.getHandler());
}
@Test
void createFunctionWithNestedPythonPackageHandler() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(
"FunctionName", "nested-python-package-handler-fn",
"Runtime", "python3.11",
"Role", "arn:aws:iam::000000000000:role/test-role",
"Handler", "apps.foo.src.lambda_handler.lambda_handler",
"Code", Map.of("ZipFile", createZipBase64("apps/foo/src/lambda_handler/__init__.py"))
));
LambdaFunction fn = service.createFunction(REGION, req);
assertEquals("apps.foo.src.lambda_handler.lambda_handler", fn.getHandler());
}
@Test
void createFunctionWithMissingHandler() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(
@@ -277,6 +303,20 @@ class LambdaServiceTest {
assertEquals("InvalidParameterValueException", ex.getErrorCode());
}
@Test
void createFunctionWithMissingNestedPythonModuleHandler() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(
"FunctionName", "missing-nested-python-handler-fn",
"Runtime", "python3.11",
"Role", "arn:aws:iam::000000000000:role/test-role",
"Handler", "apps.foo.src.lambda_handler.lambda_handler",
"Code", Map.of("ZipFile", createZipBase64("apps/foo/src/other.py"))
));
AwsException ex = assertThrows(AwsException.class, () -> service.createFunction(REGION, req));
assertEquals("InvalidParameterValueException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("apps/foo/src/lambda_handler"));
}
@Test
void createDotnetFunctionWithAssemblyHandler() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(