Flask makes it super easy to write simple web services and APIs, and Zappa makes it trivially easy to deploy them in a serverless way to AWS Lambda and AWS API Gateway. The simplest example even fits in a single .gif! We'll take an uploaded image, cut a thumbnail, and host the thumbnail on S3.First, we'll need to add a few more packages from pip:You used to have to manually compile PIL/Pillow if you wanted to use it on AWS Lambda, but since Zappa automatically uses Lambda-compatible packages via You'll notice that we're also using "render_template" now, so download The other thing to notice here is that we're base64 encoding our binary data on the client, then decoding it server-side. (we can only hope). Make sure to run the command in the virtual environment we installed Flask and Zappa into in the previous step. In the next part, we'll look at setting up our service on a domain with an free SSL certificate using Let's Encrypt.Flask makes it super easy to write simple web services and First, you'll need to set up your "virtual environment" and install Flask and Zappa into it, like so:Now, we're ready to make our application. We could use the policy generator to create our inline policy, but instead, we will create a Custom Policy written in json format.Type a policy name and paste the json below into the Policy Document window.Your AWS Account Number can be found by clicking [Support] → [Support Center]. Now that our AWS credentials are set, close the AWS IAM browser window. Next, we messed around with AWS permissions and saved an access key id and secret access key in The GitHub repo with all the code used in this post can be found here: Because our service is And you've got a serverless thumbnailing service! To shutdown the Zappa app, type the following command:In this post, we created a simple web app with Flask and deployed it to AWS Lambda with Zappa. There are a couple of layers and roles to understand: accounts, groups, users, permissions, and policies.To create the AWS credentials needed to run our web app, we need to complete a couple of steps:In the IAM Dashboard, click [Groups] on the left-hand menu. Plus, it's incredibly easy and fun!This demonstration will start with the most trivial example, and build to an example of a nearly-useful image thumbnailing service. Browse to https:///dev/upload to try it out!So, now we've seen how trivially easy it is to build serverless microservices with Flask and In the next guide, we'll learn how to deploy our microservice to a subdomain with a free SSL certificate using Let'sEncrypt. Then click the [Next: Permissions] button.In the Set permissions screen, select the group you created earlier in the Add user to group section and click [Next: Tags].Tags are optional. Hooray! At the Groups main screen, click on the group you just created to view the group's details.In the Permissions tab, under the Inline Policies section, choose the [click here] link to create a new Inline Policy.In the Set Permissions screen, click the Custom Policy radio button and click the [Select] button on the right. ), we'll create a The following files should now be in the main project directory If everything worked, you should be able to browse to the URL listed in the terminal (something like https://heq5x2wioxcz.execute-api.us-west-2.amazonaws.com/dev) and see your web app running in all its serverless glory.Pretty Cool. But an AWS Lambda function only runs when requested.Think of it this way: Cloud servers are kind of like rental cars. Install and Configure Zappa. Before you begin, make sure you have a valid AWS account, your AWS credentials file is properly installed. This took me a while to figure this out. The rental car has to be paid for even when it's just sitting in your driveway. What is Zappa? For only a trip or two in a month, Uber is pretty cheap compared to renting a car for a month.So as long as your web traffic is low, running a web app serverless on AWS Lambda is pretty cheap compared to running a regular cloud server. To increase security, you could slowly pare down the permissions and see if Zappa still deploys. But, I expect this set of security permissions may be too open. How cool is that? Who knows, maybe your app becomes super popular and your AWS bill goes through the roof? You should see Before we can deploy our serverless web app on AWS Lambda, we need to create and save a set of AWS credentials in a Turns out permissions in AWS is a complicated beast.Click the orange [Sign In to the Console] button on the upper right.Before we go any further, let's talk about permissions in AWS. Zappa should guide you through the settings it needs. Why is Zappa so great? This web app is super small and basic, but it will give you an idea of how Zappa and AWS Lambda works.The GitHub repo with all the code used in the rest of this post can be found here: Ultimately, our web app will look something like the screen capture below.Next, let's test the Flask app locally.