Lambda: runtime must be Runtime.FROM_IMAGE
when using image asset for Lambda function
#29502
Labels
@aws-cdk/aws-lambda
Related to AWS Lambda
bug
This issue is a bug.
p2
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Describe the bug
Neither
aws_lambda.Handler.FROM_IMAGE
norcdk.aws_lambda.Runtime.FROM_IMAGE
resolve when deploying a lambda using theaws_lambda.Code.fromDockerBuild
.They produce the following errors:
Handler.FROM_IMAGE
when using image asset for Lambda function"and
Runtime.FROM_IMAGE
when using image asset for Lambda function"Expected Behavior
Neither
aws_lambda.Handler.FROM_IMAGE
norcdk.aws_lambda.Runtime.FROM_IMAGE
should produce an error when deploying a lambda using theaws_lambda.Code.fromDockerBuild
.Current Behavior
Neither
aws_lambda.Handler.FROM_IMAGE
norcdk.aws_lambda.Runtime.FROM_IMAGE
resolve when deploying a lambda using theaws_lambda.Code.fromDockerBuild
.Note that I was able to resolve the first error but replacing
cdk.aws_lambda.Handler.FROM_IMAGE
with the string"Handler.FROM_IMAGE"
.I wasn't able to resolve the runtime error this way since
FunctionProps.runtime
is of typeRuntime
notstring
.Reproduction Steps
I have a repo to repsoduce the steps (use this exact commit since it's not the most recent commit):
LajosPolya/aws-cdk-templates@b92f222
Possible Solution
The interesting this about this is that both
cdk.aws_lambda.Runtime.FROM_IMAGE
andcdk.aws_lambda.Handler.FROM_IMAGE
resolve correctly when usingaws_lambda.Code.fromEcrImage
instead ofaws_lambda.Code.fromDockerBuild
.I have an example in this repo:
https://github.com/LajosPolya/aws-cdk-templates/tree/main/deploy-lambda-from-ecr
Another interesting fact about this is I'm able to deploy the Lambda successfully if I set the runtime to
cdk.aws_lambda.Runtime.NODEJS_20_X
and the handler to"index.handler"
. This seems to go against what the docs say: "UseHandler.FROM_IMAGE
when defining a function from a Docker image."This can be reproduced here:
LajosPolya/aws-cdk-templates@fc76814
Additional Information/Context
This bug was already opened once but was never fixed:
#25758
CDK CLI Version
2.133.0 (build dcc1e75)
Framework Version
No response
Node.js Version
v20.11.1
OS
Windows 10
Language
TypeScript
Language Version
"typescript": "~5.3.3"
Other information
No response
The text was updated successfully, but these errors were encountered: