When I run an AWS Lambda container (Docker) image, for example:
docker run public.ecr.aws/lambda/java bash
I get the following error:
entrypoint requires the handler name to be the first argument
What should the handler name be?
When I run an AWS Lambda container (Docker) image, for example:
docker run public.ecr.aws/lambda/java bash
I get the following error:
entrypoint requires the handler name to be the first argument
What should the handler name be?
It depends what the language is of the runtime. For example, if it is NodeJS, then the handler name should look like:
"app.handler"
If it is Java, then it should look like:
"com.example.LambdaHandler::handleRequest"
The image will look for them in LAMBDA_TASK_ROOT so you will need to make sure that your code (or compiled code) is copied to that folder when you build the image, for example:
COPY target/* ${LAMBDA_TASK_ROOT}
In my case I wanted to use the lambda image in gitlab-ci. The solution was to override the base image entrypoint by adding the following line to my Dockerfile:
ENTRYPOINT ["/bin/bash", "-l", "-c"]
Note that this means the image will not be usable in Amazon's lambdas anymore.
Guys in the thread are right, i stucked at the same place with my Node.js small script.
So, for me the right solution was adding ENTRYPOINT ["/lambda-entrypoint.sh", "helloWorldFunction.handler"]
Docker :
FROM public.ecr.aws/lambda/nodejs:14
COPY helloWorldFunction.js package*.json ./
RUN npm install
ENTRYPOINT ["/lambda-entrypoint.sh", "helloWorldFunction.handler"]
CMD [ "helloWorldFunction.handler" ]
lambda-entrypoint.sh is already placed in aws base image, don't need to add it manually
helloWorldFunction.js :
exports.handler = async (event, context) => {
return "Hello World!";
};
Also, in case you are deploying it using visual studio and AWS Toolkit - clear "image-command" field in your aws-lambda-tools-default.json as it overrides docker's CMD