Zappa is a Python library that simplifies the deployment of serverless Python web applications (WSGI and ASGI-compatible frameworks like Flask, Django, FastAPI, Bottle, Starlette, Quart) on AWS Lambda and API Gateway. It handles packaging the application and its virtual environment, configuring IAM roles, setting up API Gateway routes, and managing deployments to various stages. It is currently at version 0.62.1 and maintains an active release cadence.
pip install zappaNo compatibility data collected yet for this library.
This quickstart demonstrates how to deploy a simple Flask application to AWS Lambda using Zappa. After creating your Flask app, you initialize Zappa with `zappa init`, which guides you through creating a `zappa_settings.json` file. This file specifies your application's entry point, AWS region, runtime, and other deployment settings. Once configured, you can deploy your application with `zappa deploy <stage_name>` and manage updates or undeployments with corresponding commands. Ensure your AWS credentials are configured (e.g., via `aws configure`).
Review Zappa's changelog for 0.61.0 and update any custom scripts or configurations that might have depended on `pkg_resource` or internal `kappa` constructs. Most direct users of the CLI should not be affected.
Ensure your Lambda execution role has the necessary `lambda:InvokeFunctionUrl` permission, specifically if using function URLs. Zappa attempts to manage roles, but manual adjustments might be needed for complex policies or when `manage_roles` is set to `false` in `zappa_settings.json`.
Rename your virtual environment (e.g., `venv`, `.venv`) so its name does not conflict with your main project directory's name.
Use a Docker container with a Linux environment (e.g., `python:3.9.18-slim-bullseye` with `linux/amd64` platform) for packaging and deploying Zappa applications with native dependencies. Zappa also supports Docker-based deployments directly with the `docker_image_uri` setting.
Ensure the AWS user/role used by Zappa (`profile_name` in `zappa_settings.json`) has broad administrative access for initial setup or a finely-tuned policy allowing `lambda:*`, `apigateway:*`, `s3:*`, `logs:*`, `iam:PassRole`, `ec2:*`, and `xray:*` if X-Ray is enabled. Set `manage_roles: true` in your `zappa_settings.json` to allow Zappa to attempt to manage roles automatically.
Use Zappa's `slim_handler: true` setting in your `zappa_settings.json` to store large packages on S3 and load them at runtime, or consider using Docker-based deployments for larger projects with `docker_image_uri`.
Grant broader permissions (e.g., AdministratorAccess for testing) to your AWS user/role or specify a custom IAM policy that includes actions like `lambda:*`, `apigateway:*`, `s3:*`, and `iam:PassRole`. Ensure `profile_name` in `zappa_settings.json` refers to a profile with adequate permissions.
Run `zappa tail <stage>` to view CloudWatch logs for more detailed error messages. Check your AWS CloudFormation console for the specific stack (`<project_name>-<stage>`) to see failure reasons. If the issue persists, try `zappa undeploy <stage>` and then `zappa deploy <stage>` again after correcting any detected problems.
Verify that your `app_function` in `zappa_settings.json` (e.g., `my_project.app`) correctly points to your WSGI/ASGI application. If your virtual environment name matches your project directory name, rename the virtual environment.
Add the API Gateway execution URL (or your custom domain) to your Django `settings.py`'s `ALLOWED_HOSTS` list. For example, `ALLOWED_HOSTS = ['.execute-api.<region>.amazonaws.com', '.yourcustomdomain.com']`.