Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Deployment of a basic flask application with zappa

Setup and local deployment

  1. 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
    
  2. Install flask and zappa

     pip install flask zappa
    
  3. app.py contains a toy flask application that serves the time. Deploy it locally by running

     python app.py
    
  4. Check it works by visiting 127.0.0.1:5000/time. You should get the local time on your computer.

Deployment to AWS Lambda with zappa

  1. Configure AWS credentials, e.g. set the appropriate environment variables or put them in ~/.aws/credentials

  2. Run zappa init and accept all the defaults

  3. Run zappa deploy. The output of this command (or zappa status) includes the public amazonaws.com URL of your deployed flask application. It will look something like https://abcdef123.execute-api.us-east-1.amazonaws.com/dev/

  4. Visit your_amazonaws_url/time to check your app works. You should get the current time in the UT timezone.

Update a running Lambda deployment and tail the logs

  1. Now let's switch over to serving app2.py, which a version of our time app that supports timezones. Edit zappa_settings.json so that the line

    "app_function": "app.app",
    

    reads

    "app_function": "app2.app",
    
  2. Run zappa update

  3. Visit your_amazonaws_url/servertime to get the server time (i.e. UT)

  4. Visit your_amazonaws_url/localtime?tz=US/Pacific to get the time in the US/Pacific timezone.

  5. Visit a URL with a deliberate mistake, e.g. your_amazonaws_url/localtime?tz=US/Atlantic (this timezone does not exist). Run zappa tail to tail the logs of your application and observe the Python exception generated by your URL.