Zappa, the packager

Are you having problems with packaging your dependencies for a Lambda? You’ve done the AWS lambda python tutorials but now need to deal with something more complex? Do you just want to build a package to upload in the console or with terraform?

Zappa is a great tool to handle everything from publishing your code to have it integrated with other AWS services with the minimum modifications possible. That results in sometimes ignoring that you can use for some smaller roles, like just packaging a lambda in a zip file that you can then use on the console and/or terraform.

So, let’s imagine you have your code in a file called doing something like:

def lambda_handler(event, context):
    print('Hello World!')

To package it do the following:

1) Create a virtual environment for your function: python3 -m venv ve for python 3.6.

2) Activate the virtual environment: . ve/bin/activate (on Mac OS X or GNU/Linux) or ve/Scripts/Activate (on Windows). 3) Install zappa and other dependencies you need with pip install <dependency>. 4) Create a zappa_settings.json with the following content:

    "dev": {
        "lambda_handler": "myfunction.lambda_handler",
        "runtime": "python3.6"

5) Run zappa package dev.

6) And that’s it, with that zappa has created a zip file that you can now upload to AWS.

Want to get python/AWS tips on your email? Just subscribe!

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see