Deploy Flask App on AWS EC2 Windows
Last Updated :
24 Apr, 2024
Do you want to host a Windows-based Python Flask application on Amazon Web Services (AWS) Elastic Compute Cloud (EC2)? Flask is a frequently utilized framework for building web apps, APIs, and prototypes because of its ease of use and versatility. AWS EC2 provides virtual machines that are scalable, allowing you complete control over your deployment environment. Using Windows and Internet Information Services (IIS) as the web server, we'll take you step-by-step through the process of deploying a Flask application on AWS EC2.
What is Flask?
Flask is a Python-based web framework that is lightweight and adaptable. It offers necessary components like routing and templating in place of a cumbersome, opinionated solution. It is popular for smaller applications, quick prototyping, and developing RESTful APIs because of its simplicity.
Common Applications for Flask:
- Simple Websites: Create portfolio sites, blogs, and landing pages without adding unnecessary framework overhead.
- APIs: Provide interfaces via which programs can communicate with data.
- Prototyping: Test concepts for web applications quickly.
- Learning Tool: Flask is an excellent tool for learning web development topics due to its simplicity.
With the versatile virtual servers offered by Amazon Elastic Compute Cloud (EC2), you have complete control over your deployment environment. For developers accustomed to working with the Windows ecosystem, deploying a Flask project on AWS EC2 with Windows provides a comfortable setting.
This tutorial takes you step-by-step through the entire process.
Key Concepts Of Flask App And AWS EC2 Windows
The following are the key concepts of Flask App And AWS EC2 Windows:
- Flask is a Python web framework that offers necessary resources for creating online applications.
- EC2: Resizable virtual machines are available in the cloud through Amazon Web Services' (AWS) Elastic Compute Cloud, or AWS EC2.
- Windows Server: Microsoft operating system Windows Server is intended for use in server environments.
- IIS: Windows Server comes with a web server called IIS (Internet Information Services).
- wfastcgi: A module that makes use of the WSGI interface to allow IIS to execute Python applications.
How To Deploy Flask App On AWS EC2 Windows: A Step-by-Step Guide
Step 1: Create an EC2 Instance

- Click "Launch instance" and choose a Windows Server AMI (Amazon Machine Image). Popular options include Windows Server 2019 or 2022.

- Select an instance type suitable for your app's workload.
- Configure security groups to allow inbound traffic on ports 80 (HTTP) and any other ports your application needs.
- Launch your instance and wait for it to start.
Step 2: Connect to Your Instance
- Use Remote Desktop Protocol (RDP) to connect to your Windows instance. Get the public IP address or DNS name from the EC2 console and use your chosen RDP client (Remmina on Ubuntu).
Step 3: Install Python and Flask
- Download and install the Python installer from the official website https://www.python.org/downloads/windows/
- Open a PowerShell window on the EC2 instance.
- Install Flask using pip: 'pip install Flask'

Step 4: Setup Your Flask Application
- Create a directory for your application (e.g., 'C:\myflaskapp').
- Inside the directory, create a file named 'main.py' with your Flask application code:
Python3
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, from Flask on Windows EC2!'
if __name__ == '__main__':
app.run()
Step 5: Install and Configure IIS

- The below screenshot illustrates about the server manager Dashbaord With Loal server configuration.


- Click Next>Next and go to Server Selection
- Install "Web Server (IIS)" and include the "CGI" role service.



- Click Add Features and Install
Step 6: Install wfastcgi
- From PowerShell, install it: 'pip install wfastcgi'

- Then run the following command to enable it in the current environment.
wfastcgi-enable
Output:

Copy the path from the output
Step 7: Create Web Configuration File
- Create a file web.config next to your main flask app file "app.py".
XML
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="c:\users\Adminstrator\desktop\demoflask\env\scripts\python.exe|c:\users\Adminstrator\desktop\demoflask\env\lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="main.app" />
<add key="PYTHONPATH" value="C:\Users\Adminstrator\Desktop\DemoFlask\myProject" />
</appSettings>
</configuration>
Step 8: Configure IIS Handler
- Open IIS Manager.
- Expand your 'Sites', right-click on "Default Web Site", and select "Add Application."
- Set an alias (e.g., 'myflaskapp') and the physical path to your application's directory.
- Go to "Handler Mappings," and add a Module Mapping:
Request Path: '*'
Module: 'FastCgiModule'
Executable: 'C:\Python3x\python.exe|C:\Adminstrator\root\scripts\wfastcgi.py' (Adjust for your Python installation path)
Step 9: Test Your Application
- Click browse from the right pane to browse your site locally.
- Access your app's URL using your EC2 instance's public IP address and the alias you set (e.g., 'http://ec2-public-ip/myflaskapp')
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
AVL Tree Data Structure An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
What Is Cloud Computing ? Types, Architecture, Examples and Benefits Nowadays, Cloud computing is adopted by every company, whether it is an MNC or a startup many are still migrating towards it because of the cost-cutting, lesser maintenance, and the increased capacity of the data with the help of servers maintained by the cloud providers. Cloud Computing means stori
15 min read