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.
An alternative fix that does not require modifying the image is to override ENTRYPOINT in .gitlab-ci:
image:
name: your_image_name
entrypoint: ["/bin/bash", "-l", "-c"]
Another alternative to avoid messing with the entry point if you only need to run some commands manually could be the docker debug command.
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.
An alternative fix that does not require modifying the image is to override ENTRYPOINT in .gitlab-ci:
image:
name: your_image_name
entrypoint: ["/bin/bash", "-l", "-c"]
Another alternative to avoid messing with the entry point if you only need to run some commands manually could be the docker debug command.
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}
I'm trying to get my first real Lambda function working and I'm hitting this error when I try to run it.
entrypoint requires the handler name to be the first argument
I'm pretty new to Lambda so I'll be a bit verbose about what I'm doing and why, and I'd appreciate it if people could tell me if I'm on the right lines with my general approach too.
It's a fairly involved Python image transformation tool that needs a lot of Linux utilities, so I'm deploying it as a container image. I started out building on a bog standard AL2 image, but it looks like implementing my own runtime would have been a lot of work, and the default Python images are more extensible than I thought.
So my Dockerfile looks like this:
FROM public.ecr.aws/lambda/python:3.8
RUN yum -y update && yum install -y \
python3-pip \
...
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
RUN pip3 install -r lrd-requirements.txt --target "${LAMBDA_TASK_ROOT}"
COPY app.py "${LAMBDA_TASK_ROOT}"
CMD [ "app.lambda_handler" ]And my app.py is like this (ignore the indentation in the handler, Reddit wasn't playing ball):
# import the necessary packages
import os
import sys
import requests
...
def lambda_handler(event, context):
print("Main triggered \n")
image_name,receipt_handle = image_download(download_path)
input_file_path = prep_files(download_path)
process_image(input_file_path,image_name,render_factor,upload_bucket,output_path,receipt_handle)
image_upload(results_img_directory,image_name,upload_bucket,receipt_handle)
delete_sqs_message(queue,receipt_handle)
print("End of main")So as far as I can tell I'm doing everything right according to all advice I've read, so can anyone see what's going wrong here please?
Laravel Queue Dockerfile: entrypoint requires the handler name to be the first argument
entrypoint requires the handler name to be the first argument
aws batch failure: "entrypoint requires the handler name to be the first argument"
docker - Using argument in CMD for a Dockerfile(entrypoint requires the handler name to be the first argument) - Stack Overflow
I ran across this answer when suffering from the same issue, but came to a possibly simpler solution.
As I could not provide the handler through CMD I simply overrode the ENTRYPOINT - this is perhaps not ideal, but having looked at the contents of the /lambda-entrypoint.sh I don't see any concerning impact
The /lambda-entrypoint.sh provided in the image looks like this
sh-4.2# cat /lambda-entrypoint.sh
#!/bin/sh
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
if [ $# -ne 1 ]; then
echo "entrypoint requires the handler name to be the first argument" 1>&2
exit 142
fi
export _HANDLER="$1"
RUNTIME_ENTRYPOINT=/var/runtime/bootstrap
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
exec /usr/local/bin/aws-lambda-rie $RUNTIME_ENTRYPOINT
else
exec $RUNTIME_ENTRYPOINT
fi
So I override the ENTRYPOINT in my final stage as follows
FROM runtime
ARG FUNCTION_HANDLER
ENV FUNCTION_HANDLER=${FUNCTION_HANDLER}
COPY --from=publish ./app/out .
ENTRYPOINT /lambda-entrypoint.sh ${FUNCTION_HANDLER}
The ARG sets the stage to use the build arg provided. The ENV then sets the value in the runtime environment. The ENTRYPOINT then overrides the default entrypoint passing the handler name.
I did end up solving this doing something similar to what Hans Kilian suggested. Hardcoded a lambda name, and had that call the specific handler that I required.
» npm install @bitblit/epsilon
LAMBDA_TASK_ROOT is Lambda’s predefined env variable for the code runtime.
The image will look for it in the LAMBDA_TASK_ROOT so you need to make sure that your code is copied to that folder when the image is built.
I was able to resolve the issue by updating my Dockerfile to the following:
FROM bref/php-80-fpm
RUN curl -s https://getcomposer.org/installer | php
RUN php composer.phar require bref/bref
COPY . /var/task
ENTRYPOINT php index.php $CONTROLLER $FUNCTION
And then set environment variables to serve as $CONTROLLER and $FUNCTION
Note that you can test this without setting environment variables for example if I want to run a function called profile_update within my customers controller then I could use ENTRYPOINT php index.php customers profile_update
As far as I understand it the ENTRYPOINT here is equivalent to a command line function for running a script on my app, or the equivalent of what I would use for a cron command. In my app it follows the above format and this worked to resolve my error.
I'm trying to deploy a lambda passing the function as a build ARG, but getting the following error "entrypoint requires the handler name to be the first argument" If I hardcode the handler into the Dockerfile CMD this builds and functions. What am I missing?
``FROM public.ecr.aws/lambda/python:3.8
ARG FUNCTION
ENV HANDLER=$FUNCTION
...Stuff...
CMD "${HANDLER}``