I am working to set up AWS Lambda with a PHP application. I have been able to set up the basic functionality as documented here: https://aws.amazon.com/blogs/compute/building-php-lambda-functions-with-docker-container-images/
I have the following Dockerfile:
FROM bref/php-80-fpm
RUN curl -s https://getcomposer.org/installer | php
RUN php composer.phar require bref/bref
COPY . /var/task
CMD _HANDLER=index.php /opt/bootstrap
When I run a test on Lambda I get an error: entrypoint requires the handler name to be the first argument
I see in the linked post above there is a comment in the Dockerfile stating that this line sets the entry point:
#set the function handler entry point
CMD _HANDLER=index.php /opt/bootstrap
But I’m not sure what that line means. The index.php file should be used as an entrypoint for my app but I don’t know what /opt/bootstrap
does.
Is someone able to explain what the entrypoint here is and how I would troubleshoot it?
2
Answers
I was able to resolve the issue by updating my Dockerfile to the following:
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 mycustomers
controller then I could useENTRYPOINT 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.
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.