Serverless development evolves: Why my team uses Zappa

Serverless architecture has quickly emerged as the up-and-coming way to develop cloud-based applications. The benefits of serverless computing—zero server maintenance, out-of-the-box scalability, and ground-up support for asynchronous workflows—are just too good to ignore. It’s a developer’s dream.

But serverless architecture comes with a catch. These operational advantages carry a hefty price for developers: laborious configuration, immature frameworks, a lack of tooling, and a dearth of established design patterns. Until recently, going serverless meant throwing out decades of established tools and practices and starting over. In a nutshell, making serverless apps can be painful.

That's why I selected the open-source Zappa as my serverless Python framework on a recent project for a dotcom start-up. I wanted to eliminate the burden of server maintenance for the young company and to design a cost-effective cloud architecture that was cheap when traffic was low. 

I wanted something that would scale as the company grew. But I wanted these benefits without the unpleasant side effects that I’d encountered when working on serverless apps. After doing the research, it became clear that Zappa embodied the culmination of the progress that serverless technology has made over the last 18 months. Here's why.

The State of Analytics in IT Operations

Serverless evolution: From SAM to Zappa

The serverless evolution began when Amazon Web Services (AWS) open sourced its Serverless Application Model (SAM). SAM is a simplified template syntax for CloudFormation, AWS’s infrastructure-as-code framework, that reduced the jaw-dropping amount of code previously required to automate the deployment of serverless apps.

SAM made configuration a little better for some uses, but it was only an incremental improvement. The fundamental problem still remained: Developing applications as Lambda functions required starting over with new design patterns and Lambda-compatible libraries. For the Python crowd, this meant kissing time-saving application frameworks such as Django and Flask goodbye.

Fortunately, the universe of supporting tools and frameworks has evolved rapidly thanks to another AWS release, version 1.0 of Chalice, a Python framework and command-line utility for serverless application development. Chalice provides some neat features, such as automatically generating an IAM security policy based on an inspection of your code (this is amazing, I’m not going to lie), but it still doesn’t provide the application scaffolding that we’ve come to rely on for rapid application development.

Enter Zappa, an open-source project maintained by the smart folks at gun.io. Zappa is a full-featured command-line tool that Lambda-fies Flask and Django applications. Technically speaking, it’s a framework that packages and deploys WSGI-compatible Python applications to an AWS Lambda function. Zappa is an "easy button" for Flask and Django serverless deployment.

With Zappa, you can have your cake and eat it too. You can develop applications locally using your favorite IDE, continue writing code using the Python libraries that you’ve come to rely on, and use best practice design patterns. Then, when it’s time to deploy, you just run "zappa deploy" at the command line to package up your traditional app and deploy it to AWS Lambda. Voilà!

There is no such thing as a free lunch. As with any framework, Zappa takes time to learn, and it has its quirks. But Zappa is much easier to get started with and has far fewer quirks than most open-source frameworks. Given the enormous benefit it provides—combining the power of serverless deployment with the ease of traditional application development—it’s well worth the small investment in ramp-up time.

What I like about Zappa

Here are a few of the features that Zappa provides that I find particularly compelling:

  • Good documentation: The Zappa README page provides simple, but comprehensive, documentation.
  • The Quick Start Wizard: Zappa has a neat interactive wizard that helps you set up Zappa projects quickly when you’re first getting started.
  • Automated deployment: This is Zappa’s superpower—the ability to automagically package and deploy plain-old Flask or Django apps to an AWS serverless app. With a single command, you can deploy, update, or destroy an application for a specified stage (e.g., dev, staging, production).
  • Automated rollback: In addition to deployments, you can roll back a Zappa application with a single command. Zappa uses AWS Lambda’s native versioning to do this.
  • Keep-warm feature: By default, Zappa creates a scheduled Lambda function that keeps the container from getting decommissioned due to inactivity by pinging it every four minutes, avoiding a potential performance hit.
  • The settings file: Once you become familiar with Zappa, you’ll manage your project configuration directly in the Zappa settings file. This is a simple YAML or JSON file that stores your project configuration for each stage.
  • Environment variables: Within the Zappa settings file, you can store environment variables that can be accessed by your app when it’s deployed. Zappa also handles secret environment variables (e.g., a database connection string that you don’t want in source control) by allowing you to reference an S3 bucket that contains a settings file with the secrets.
  • Continuous delivery: Zappa was built with CI/CD pipelines in mind. So instead of using Zappa to deploy the application directly, you can use it to generate a CloudFormation template and zipped code package for your own DIY deployment.
  • Debugging with the tail command: This Zappa command makes debugging Lambda functions a little easier. You can watch the CloudWatch logs directly from the command line and filter the results the CloudWatch log filtering syntax.
  • Default or custom IAM policy: By default, Zappa creates an identity and access management (IAM) policy that provides enough permissions to get started right out of the box for most use cases. In production, however, you’ll want to specify a custom IAM policy that's tailored to your specific application to ensure that it adheres to the principle of least privilege.
  • Scheduled Lambda jobs: Zappa lets you run Lambda functions at regular intervals. This is helpful when you have small maintenance tasks to run but don’t want to spend a lot of time scheduling and managing CloudWatch jobs.
  • SSL certificates: Zappa has a certify command that lets you use DevOps-friendly certs from AWS and Let’s Encrypt (as well as SSL certs from other providers) for your Lambda’s Custom Domain.
  • X-ray integration: X-Ray is AWS’s new service for monitoring application performance across microservices. You can add X-ray integration to your app with a simple addition to the Zappa settings file. Once this is enabled, the Python libraries that implement X-ray instrumentation become available in your app.
  • Cognito user pools: If you’re using AWS Cognito to manage user pools and authentication, Zappa’s got you covered. You can specify your user pool ID in the Zappa settings file, and Zappa will create an API gateway authorizer to handle the token-based authentication.
  • Global deployments: The Zappa framework can deploy your application globally, in multiple AWS regions. This provides better performance for apps with geographically distributed users and creates redundancy when an entire region goes down (which happens).
  • T-shirts: The best thing about Zappa is that they have T-shirts. There's a Zappa Flask T-shirt and a Django one. How cool is that?

Zappa is a remarkably full-featured framework, especially given the newness of serverless development. But what I like the most about developing applications with Zappa is that when the framework doesn’t cover a particular use case; it stays out of the way when I need to write custom code to address it.

Too often, developers spend more time managing the framework than building the app. Not so with Zappa. It strikes the right balance between being full-featured and lightweight.

Serverless development has come a long way in a short amount of time, and with frameworks such as Zappa, I dare say, it has actually become … fun.

How are you using Zappa? What do you like, or not like, about the framework? I welcome your thoughts and comments below. 

[ Upcoming Webinar (Oct. 23): Simplify Discovery and Change Management for Cloud and Container Environments ]