Deploying a Flask application to AWS

Published Feb 12, 2018Last updated May 23, 2018


What is Flask ?

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.Flask is awesome and it is the easiest way to learn web development. Start small, and then you can quickly add any upgrades you need — email, databases, forms, etc.

What is AWS ?

Amazon Web Services (AWS) is a subsidiary of that provides on-demand cloud computing platforms to individuals, companies and governments, on a paid subscription basis. Amazon Web Services is truly fantastic. There are a ton of cloud platforms out there, but none are more flexible than AWS. It seems like you can do anything on Amazon — host websites, create scalable databases, send emails, text messages, stream live video from your home — the possibilities are endless.

So, it seems a natural fit to create a flask application and push it to AWS.

Although, there are some excellent blog posts that help with stumbling blocks, but I couldn’t find an easy example for deploying a Flask application to AWS.

So here’s a step-by-step tutorial that will launch your Flask application to AWS EE2 instance.

The post consists of the following steps :-

  1. Setting up an account on the AWS.
  2. Creating an AWS EC2 instance under the free tier with the required settings.
  3. Coding the flask application and deploying it to the EC2 instance.
  4. Accessing the flask application from anywhere.

Now, lets dive deep into the steps :-

Step 1 - Setting up an account on AWS

Sign up on Amazon Web Services.

Note: AWS requires a credit card for registration. But our example will exist entirely on the AWS Free Tier, so you won’t be charged.

Step 2 - Creating an EC2 instance

This step consists of the following steps :-

  • Select the EC2 option under the Compute section.


  • Select the Launch Instance option under the Create Instance section.


  • Select the Linux AMI machine eligible under free tier.


  • Select the General Purpose t2.micro type instance under the free tier.


  • Next, Leave Step 3 as it is and move to the Add Storage section.


  • Leave Step 4 : Add Storage and Step 5 : Add Tags as it is and move to Step 6 : Configure Security Groups.



  • In Step 6, configure the security groups as shown in the following figure :


Finally, review and launch the instance by using an existing key pair or creating a new key pair.

Step 3 - Connecting to the instance and coding the Flask application

To connect to your EC2 instance, follow the steps discussed in this link.

Once you have connected to your EC2 instance, install flask on it using the command sudo pip install flask.

Once flask is installed, create a file called and paste the following code :

from flask import Flask
app = Flask(__name__)

def hello_world():
    return 'Hello, World!'

if __name__ == "__main__":"", port=80)

Now, run the code using the following command sudo python

Step 4 - Accessing the Flask application

To access the flask application, visit the IPv4 Public IP of your EC2 instance as given in the instance dashboard.


To access the flask application deployed on the instance in the above figure,visit the IP of the instance - and get the following output :


Feel free to suggest changes and point out bugs.

Hope you found this helpful 😄

Discover and read more posts from Dushyant Rathore
get started