fix(lambda): defer handler validation to invocation (#3332)

Fixes #3311
This commit is contained in:
BingEdward authored and GitHub committed 2026-09-10 08:09:46 -04:00
1 parent 8a4c6494ed
commit 8b25e5003d
3 files changed
+18 -53

No files matched your search

@@ -34,6 +34,9 @@ class LambdaLayerIntegrationTest {
zos.putNextEntry(new ZipEntry("nodejs/node_modules/my-lib/index.js"));
zos.write("module.exports = { hello: () => 'world' };".getBytes());
zos.closeEntry();
zos.putNextEntry(new ZipEntry("python/entrypoint.py"));
zos.write("def lambda_handler(event, context): return {'from': 'layer'}".getBytes());
zos.closeEntry();
}
return Base64.getEncoder().encodeToString(baos.toByteArray());
}
@@ -58,7 +61,7 @@ class LambdaLayerIntegrationTest {
.body("""
{
"Content": { "ZipFile": "%s" },
"CompatibleRuntimes": ["nodejs20.x", "nodejs22.x"],
"CompatibleRuntimes": ["nodejs20.x", "nodejs22.x", "python3.12"],
"CompatibleArchitectures": ["x86_64"],
"Description": "Shared utilities v1",
"LicenseInfo": "MIT"
@@ -73,7 +76,7 @@ class LambdaLayerIntegrationTest {
.body("LayerVersionArn", containsString(":layer:" + LAYER_NAME + ":1"))
.body("Description", equalTo("Shared utilities v1"))
.body("LicenseInfo", equalTo("MIT"))
.body("CompatibleRuntimes", hasItems("nodejs20.x", "nodejs22.x"))
.body("CompatibleRuntimes", hasItems("nodejs20.x", "nodejs22.x", "python3.12"))
.body("CompatibleArchitectures", hasItem("x86_64"))
.body("Content.CodeSize", greaterThan(0))
.body("Content.CodeSha256", not(emptyString()))
@@ -188,15 +191,15 @@ class LambdaLayerIntegrationTest {
@Test
@Order(9)
void createFunction_withLayers_storesLayerArns() throws Exception {
void createFunction_acceptsHandlerProvidedByLayer() throws Exception {
given()
.contentType("application/json")
.body("""
{
"FunctionName": "%s",
"Runtime": "nodejs20.x",
"Runtime": "python3.12",
"Role": "arn:aws:iam::000000000000:role/lambda-role",
"Handler": "index.handler",
"Handler": "entrypoint.lambda_handler",
"Code": { "ZipFile": "%s" },
"Layers": ["arn:aws:lambda:us-east-1:000000000000:layer:%s:1"]
}
@@ -538,7 +538,7 @@ class LambdaServiceTest {
}
@Test
void createFunctionWithMissingHandler() throws Exception {
void createFunctionDoesNotValidateHandlerAtDeployTime() throws Exception {
Map<String, Object> req = new java.util.HashMap<>(Map.of(
"FunctionName", "missing-handler-fn",
"Runtime", "nodejs20.x",
@@ -546,22 +546,24 @@ class LambdaServiceTest {
"Handler", "src/index.handler",
"Code", Map.of("ZipFile", createZipBase64("other.js"))
));
AwsException ex = assertThrows(AwsException.class, () -> service.createFunction(REGION, req));
assertEquals("InvalidParameterValueException", ex.getErrorCode());
LambdaFunction fn = service.createFunction(REGION, req);
assertEquals("src/index.handler", fn.getHandler());
}
@Test
void createFunctionWithMissingNestedPythonModuleHandler() throws Exception {
void updateFunctionCodeDoesNotValidateHandlerAtDeployTime() 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"))
"Code", Map.of("ZipFile", createZipBase64("apps/foo/src/lambda_handler.py"))
));
AwsException ex = assertThrows(AwsException.class, () -> service.createFunction(REGION, req));
assertEquals("InvalidParameterValueException", ex.getErrorCode());
assertTrue(ex.getMessage().contains("apps/foo/src/lambda_handler"));
service.createFunction(REGION, req);
LambdaFunction fn = service.updateFunctionCode(REGION, "missing-nested-python-handler-fn",
Map.of("ZipFile", createZipBase64("apps/foo/src/other.py")));
assertEquals("apps.foo.src.lambda_handler.lambda_handler", fn.getHandler());
}
@Test