-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lambda: runtime must be Runtime.FROM_IMAGE
when using image asset for Lambda function
#29502
Comments
Let's simplify the code. I guess you should use const dockerImageCode = lambda.Code.fromDockerBuild(
path.join(__dirname, '../docker-function.d')
);
const fn = new lambda.Function(this, 'Fn', {
runtime: lambda.Runtime.FROM_IMAGE,
code: dockerImageCode,
handler: lambda.Handler.FROM_IMAGE,
}); But if you look at the source code here, DockerImageFunction is generally recommended in your use case. aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/image-function.ts Lines 63 to 75 in 87139ab
Why not just use DockerImageFunction in your use case? |
I wasn't aware of this option. I was able to test this and it works! Thanks for the suggestion @pahud |
|
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: