I wanted to setup a simple dockerized API with Serverless Framework. I do something wrong, because CloudWatch is throwing me Runtime.InvalidEntrypoint error once I access the Lambda function URL.
My commands I used are:
- npm init -y
- serverless deploy
Both successful.
Error:
INIT_REPORT Init Duration: 4.66 ms Phase: init Status: error Error Type: Runtime.InvalidEntrypoint
INIT_REPORT Init Duration: 0.58 ms Phase: invoke Status: error Error Type: Runtime.InvalidEntrypoint
START RequestId: 42c8d6e8-e848-461c-a6bd-5eebb839d86b Version: $LATEST
RequestId: 42c8d6e8-e848-461c-a6bd-5eebb839d86b Error: fork/exec /lambda-entrypoint.sh: exec format error Runtime.InvalidEntrypoint
./app.js
"use strict";
module.exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify(
{
message: `Hello, world!`,
},
null,
2
),
};
};
./Dockerfile
FROM public.ecr.aws/lambda/nodejs:18
COPY package.json ./
RUN npm install
COPY app.js .
CMD ["app.handler"]
./serverless.yml
service: lambda-hello
provider:
name: aws
region: ap-southeast-1
ecr:
images:
appimage:
path: ./
functions:
hello:
image:
name: appimage
command:
- app.handler
events:
- http:
path: /{any+}
method: any
Making the API runnable & accessable.
I’ve faced a similar issue in the past and in my case, the issue was with the way the Lambda entry point was configured in my Dockerfile, which is quite similar to what you’ve shown. You can read more about working with lambda container images here
Usually, AWS Lambda base images handle the command and entry point internally, and you shouldn’t need to specify them explicitly if your handler is written in the supported language and follows the expected naming conventions, which you’ve already done.
The handler you’ve specified in the function's definition within the Serverless Framework configuration (
serverless.yml) file is good. So just modify your Dockerfile to take out the last line:After making the change to your Dockerfile, rebuild your Docker image, and redeploy your service using Serverless Framework:
With these changes, AWS Lambda will automatically use the entry point defined in the base image, and it will locate your handler based on the
commandspecified inserverless.yml.