Choosing a Python Serverless framework
Recently we needed to do a round of prototyping on a new product we are working on. We wanted to be able to quickly setup a Python web application but we didn’t want to create or manage a lot of infrastructure around it, unlike our production applications.
Having followed some of the experiences of other small startups we felt that trying to deploy our application via AWS Lambda would provide a low cost, low fuss environment where we could play around with different takes on ideas.
While we’ve created some Lambda’s before they were task-based rather than full web-applications. Essentially they were just single Python scripts that responded to a particular event with a limited set of actions.
There are a number of frameworks that solve this problem and as we wanted to focus on creating a working application quickly rather than doing the plumbing it made sense to pick a framework and work with it.
The obvious choice was Serverless which is one of the most popular frameworks in the space and has a lot of community support. However we wanted to use Python to avoid having to switch language contexts from our day to day work.
Another option would have been Chalice. It is written in Python and has been created and supported by AWS themselves. Sounds great!
The downside is that Chalice is a brand new framework and while familiar in style it would require us to learn a new and slightly different way of developing a webapp which isn’t what we were ideally looking for.
That brings us to Zappa which is essentially a Lambda wrapper for WSGI applications. One of the team had already created a sample application previously with it using the Bottle framework.
As we had also been experimenting with a more conventional AMI and ASG configuration using Flask we thought that if we could create a conventional Flask web application and deploy it with Zappa we would have a simple fallback plan if it didn’t work out.
Zappa is, at heart, a CLI tool and data configuration file that deploys a conventional WSGI Flask application into an AWS Lambda framework. Dependencies and local development are exactly the same as a regular Flask development and the deployment tool painlessly created an AWS environment that was quickly available but where costs are directly related to usage. Perfect for prototyping!