Zappa provides easy way to deploy server-less Python applications on AWS Lambda with API Gateway.

In AWS CLI, S3 And Boto3 we have explained how to configure AWS Command Line Interface (CLI).

Now let’s create simple Flask app. Before we do this, create a directory simple-flask-app and new empty python’s virtual environment. Zappa recommends to name it differently than the project, for example simple-flask-app-venv. We refer you, for example, Pyenv and VirtualEnvs for instructions about how to create virtual env with pyenv).

Now let’s install needed packages by creating requirements.txt with

Flask==1.1.2
zappa==0.51.0

and then run:

pip install -r requirements.txt

Creating app

Create file random_app.py with

import random
import json

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    random_number_dict = {
        'randomNumber': random.random()
    }
    return json.dumps(random_number_dict)

You can test app with

export FLASK_APP=random_app.py; flask run

Zappa

First init zappa by

zappa init

When it asks “What do you want to call this environment (default ‘dev’):”, you can choose dev. Then choose your profile and do deploy the app globally.

Finally run:

zappa deploy dev

When you change app, use:

zappa update dev

Updated: 2020-04-12