AWS Builder Center

Deploying Your First Python Flask Application on AWS EC2

A step-by-step guide to taking your local Python Flask web application and deploying it to the cloud using Amazon EC2. Learn how to transition from a development environment to a live cloud server.

Building a web application locally using Python and Flask is a great milestone for any developer. Whether you are building a restaurant management system or a rental discovery platform, seeing your application run on  localhost:5000  is incredibly satisfying. But the real magic happens when you push that application to the cloud so users anywhere can access it.
In this guide, we will walk through how to deploy a basic Python Flask application on an Amazon EC2 instance.

Prerequisites

  • An active AWS Account
  • Basic knowledge of Python and Flask
  • Familiarity with the Linux command line

Step 1: Launch an Amazon EC2 Instance

  1. Log into your AWS Management Console and navigate to the EC2 Dashboard.
  1. Click Launch Instance.
  1. Name your instance (e.g.,  flask-web-server ).
  1. Select Ubuntu Server as your Amazon Machine Image (AMI). The free-tier eligible option is perfect for this.
  1. Choose an instance type (e.g.,  t2.micro ).
  1. Create a new Key Pair (select  .pem  format) and download it. You will need this to SSH into your server.
  1. Under Network Settings, ensure you allow SSH traffic, HTTP traffic, and HTTPS traffic.
  1. Click Launch Instance.

Step 2: Connect to Your Instance

Once your instance is running, open your terminal and navigate to the folder where you downloaded your key pair. Run the following commands:
Bash
# Change permissions on your key file
chmod 400 your-key-pair.pem
# Connect to the instance (replace the IP with your instance's Public IPv4 address)
ssh -i "your-key-pair.pem" ubuntu@<your-ec2-public-ip>

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article