How to Run Docker Containers on AWS Lambda?

Let’s put a PHP application right into the serverless cloud

Jakub Kapuscik
The Startup

--

Photo by Bernd Dittrich on Unsplash

AWS Lambda and serverless approach can give a wide range of benefits. Unfortunately, Lambda does not have native support for PHP and it has not been that easy to run PHP applications here. One of the big announcements from the AWS re:Invent 2020 was the Lambda container image support. It creates huge possibilities and from now on we easily move any technology stack that we wish directly into the serverless cloud.

Let’s assume that we have a PHP REST API that has relatively low average usage and high peaks in unpredictable time intervals. Moving it to lambda will assure concurrent execution and allow scaling out as needed with extremely low costs. The application is based on PHP 8 and is using Nginx as the webserver. The key drivers of the migration are to release it as fast as possible and ensure a similar execution environment as the legacy one with little to no source code changes. With container image support we can wrap everything into a Docker image and deploy it directly to Lambda. Let’s see how it can be done.

Full source code is available here:

--

--