Deploying Django Docker Images To AWS Lambda Container
A proof of concept way to deploy a Django image to AWS Lambda
As of Dec 2020, AWS Lambda functions can be packaged and deployed as containers images. This new change has significant implications, it allows the developer to take advantage of the benefits provided by AWS lambda i.e. operational simplicity, automatic scaling, high availability etc, without some of the limitations associated i.e. it can be difficult to deploy custom native binaries such as ffmpeg or gdal to it.
It is worth noting that one can deploy such binaries using AWS Lambda Layers to solve some of this challenges, but it is less natural than packaging all the required dependencies as a single image.
The advantage of using containers as opposed to layers is that there is a level of familiarity with container tooling, workflows and dependencies. However, since lambda containers are a new thing (when this document was written), there is little documentation regarding how to deploy a Django application image to Lambda and no existing tooling that exists of how to do this(to my knowledge). Currently the conventional way to deploy Django applications directly into AWS Lambda, is by using the Zappa python library. The library makes it easy to build and deploy sever-less, event-driven Python applications.
With this in mind, this blog offers a proof of concept way to deploy a Django image as a container to AWS Lambda. The hope is that in the next few months there will be tooling available to make the process more seamless. It is designed for developers who want to experiment with this technology early on.
The associated Github repository for this blog is on https://github.com/gitumarkk/django_aws_lambda_containers.git
The Lambda Runtime
Currently AWS provides base images that support Lambda runtimes for Python. This means it is easy to add code and dependencies to your application. You can also build your own images using custom python base images i.e. alpine, slim or buster images and so on. The caveat to using the python base images is that they need to implement the Lambda Runtime Api. This simply means your image must be invoked in the same way a lambda function is…