Flask Lambda Lab – Lesson 3

Lesson Overview

In this lesson, we will download a more sophisticated version of the flask app from a git branch of our original project called `lesson2`. This version of the application uses Bootstrap css and js libraries to make the web page easier on the eyes. We’ll also expand the application code to use flask templates and add a few pages to the site

Lesson Lab

  1. Clone flask lesson 2 from github (add some interesting web content & css)
    cd ~/flask_lambda_lab 
    git checkout lesson2 -f
  2. Create a couple of s3 buckets for our gallery application
    • This script will create two s3 buckets. One for image uploads and the other for image thumbnails. The script will set public-read permissions to the bucket, enable web access for the buckets and authorize CORS (cross origin resource sharing). Finally, it will store the bucket names in a config file called bucketConfig.py so that our flask app can find them
      ./create_s3_buckets.py
  3. Deploy flask app w/ zappa to AWS lambda
    • NOTE: if you are using an environment name different than dev, substitute it below
      zappa deploy dev
  4. Test access to web application via API gateway
    • Browser: https://……execute-api.us-west-2.amazonaws.com/dev
    • Upload a .jpg or .png file to the `Uploads` page.
    • See the uploaded list of files on the `Gallery` page
  5. Using the AWS console, go you your S3 uploads bucket
    • Validate that the image files exist
    • Look at one of the image’s Metadata
    • S3 Open File > Properties > Metadata
    • Notice that only the default attribute (Content-Type) is set. In the next lesson, we will store some additional info here

Lesson Summary

In this lesson, we:

  1. Downloaded a more functional version of our flask app to the EC2 dev server
  2. Created a couple of s3 buckets that to store uploaded image files
  3. Deployed that application to lambda with zappa
  4. Uploaded some image files to our S3 bucket through the flask app
  5. Validated the uploads in s3 and looked at s3 file metadata

But a gallery without thumbnails isn’t very useful. In Lesson 4, we’ll configure an s3 trigger to call a lambda function and create a thumbnail