- Newest
- Most votes
- Most comments
The issue you're experiencing is likely due to how AWS Lambda expects container images to be structured and how it handles the execution of functions. When using a custom runtime or container image with Lambda, there are specific requirements that need to be met.
-
Entry Point: Your Dockerfile is using CMD to specify the entry point, but Lambda expects an ENTRYPOINT instruction instead. The ENTRYPOINT should point to the Lambda runtime interface client, which handles the communication between Lambda and your function code.
-
Handler Function: Lambda expects a handler function that it can invoke, rather than directly executing a script. Your current setup is running the PHP script directly, which doesn't align with how Lambda typically operates.
To fix this, you'll need to make a few changes:
- Modify your Dockerfile to include the Lambda runtime interface client and set it as the ENTRYPOINT.
- Create a PHP handler function that Lambda can invoke.
- Use CMD in your Dockerfile to specify the handler function.
Here's an example of how you might modify your Dockerfile:
FROM php:8.3-cli-alpine3.21 # Install the Lambda Runtime Interface Client RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN composer require bref/bref WORKDIR /var/task COPY . . # Set the Lambda Runtime Interface Client as the ENTRYPOINT ENTRYPOINT ["/opt/bref/runtime/php/bootstrap"] # Specify your handler function CMD ["index.php"]
Then, create an index.php file with a handler function:
<?php function handler($event, $context) { echo "test"; return ['statusCode' => 200, 'body' => 'Hello from PHP Lambda!']; }
This setup should resolve the Runtime.ExitError you're experiencing and allow your PHP function to run properly in Lambda. Remember to adjust your Lambda function configuration to point to the correct handler (e.g., "index.handler").
For more complex scenarios, like running Symfony commands, you may need to adapt this approach further, possibly by creating a custom runtime that can execute your Symfony commands within the Lambda environment.
Sources
AWS Lambda: Runtime.InvalidEntrypoint | AWS re:Post
Lambda Function built using Docker Image cannot find the lambda handler function | AWS re:Post
answered 2 years ago
Relevant content
asked 4 years ago
asked 4 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago

I've also found this article which is great but does not solve my problem (nor do your answer unfortunatelly) - https://aws.amazon.com/blogs/apn/aws-lambda-custom-runtime-for-php-a-practical-example/
Can you collaborate on how would I use this approach (either one - bref or custom runtime form my example) to run commands in Symfony console?
https://symfony.com/doc/current/components/console.html
My console file looks something like this: