-
Create and activate a virtual environment (note you must create a fresh virtual environment to use zappa), e.g.
python -m virtualenv venv && source venv/bin/activate
-
Install flask and zappa
pip install flask zappa
-
app.py
contains a toy flask application that serves the time. Deploy it locally by runningpython app.py
-
Check it works by visiting
127.0.0.1:5000/time
. You should get the local time on your computer.
-
Configure AWS credentials, e.g. set the appropriate environment variables or put them in
~/.aws/credentials
-
Run
zappa init
and accept all the defaults -
Run
zappa deploy
. The output of this command (orzappa status
) includes the publicamazonaws.com
URL of your deployed flask application. It will look something likehttps://abcdef123.execute-api.us-east-1.amazonaws.com/dev/
-
Visit
your_amazonaws_url/time
to check your app works. You should get the current time in the UT timezone.
-
Now let's switch over to serving
app2.py
, which a version of our time app that supports timezones. Editzappa_settings.json
so that the line"app_function": "app.app",
reads
"app_function": "app2.app",
-
Run
zappa update
-
Visit
your_amazonaws_url/servertime
to get the server time (i.e. UT) -
Visit
your_amazonaws_url/localtime?tz=US/Pacific
to get the time in the US/Pacific timezone. -
Visit a URL with a deliberate mistake, e.g.
your_amazonaws_url/localtime?tz=US/Atlantic
(this timezone does not exist). Runzappa tail
to tail the logs of your application and observe the Python exception generated by your URL.