- Launch an EC2 instance to host a Flask app.
- Connect to the instance and install packages.
- Clone and run the sample app.
- Verify the web app is reachable externally.
- Attempt a data submission (expected to fail due to missing DB configuration).
Step 1 — Launch an EC2 instance
- Open the EC2 console (use the AWS console search bar).
- Click Launch Instance and give the instance a name, for example:
User Information App. - Choose the Amazon Linux AMI.
- Create or select a security group. For this demo we allow SSH from anywhere, but in production restrict SSH to your IP address only.

For security, do not open SSH (port 22) to 0.0.0.0/0 in production. Restrict SSH inbound access to specific IP addresses or your administrator network.

Step 2 — Connect to the EC2 instance
- Select the instance in the console and click Connect.
- Use EC2 Instance Connect to open a browser-based terminal. For Amazon Linux the username is typically
ec2-user.

Step 3 — Get the application code from GitHub
On the repository page click Code and copy the HTTPS URL for cloning.
git is not installed you will see an error like:
Step 4 — Clone the repo and inspect the app
Clone the repository and change into the app folder:Step 5 — Install Python dependencies and attempt to start the app
Try running the Flask app:templates folder). Install the required Python packages:
Tip: For cleaner dependency management, create and activate a Python virtual environment (venv) instead of installing packages globally. This prevents permission conflicts and keeps dependencies isolated.
Step 6 — Start the Flask application
Return to the app folder and start the app:The built-in Flask server is for development and testing only. For production, use a WSGI server such as Gunicorn or uWSGI and place it behind a reverse proxy (Nginx, Apache).
Step 7 — Open port 5000 in the instance security group
By default the security group created during instance launch may only allow SSH (22), HTTP (80), and HTTPS (443). Port 5000 is not open, so the Flask app won’t be accessible externally until you add an inbound rule.
| Type | Protocol | Port range | Source | Use case |
|---|---|---|---|---|
| SSH | TCP | 22 | Your IP (e.g., 203.0.113.4/32) | Secure shell access (restrict this) |
| HTTP | TCP | 80 | 0.0.0.0/0 | Web traffic (optional) |
| HTTPS | TCP | 443 | 0.0.0.0/0 | Encrypted web traffic (optional) |
| Custom TCP | TCP | 5000 | Your IP or 0.0.0.0/0 (demo) | Flask dev server port for testing |
Step 8 — Access the application in a browser
Copy the instance’s public IPv4 address from the EC2 console and open the Flask app in a browser: http://<PUBLIC_IP>:5000 You should see the “User Details” form served by the Flask app:
Step 9 — Submit data (expected failure)
The app displays a form to collect user details. If you submit the form now, the app will likely fail to connect to a database and return an error like “Failed to connect to the database.” This is expected — you have not yet configured RDS connection details (endpoint, port, username, password, database name) or the necessary network access (VPC, security group, routing).
Next steps — Connect the app to RDS (not covered in this lesson)
To complete the deployment and persist form submissions you will need to:- Create an RDS instance (MySQL/Postgres) or use an existing database.
- Provide the application with the database endpoint, port, username, password, and database name (edit config or environment variables in the app).
- Ensure network connectivity: place EC2 and RDS in the same VPC/subnet or allow routing, and update security group inbound/outbound rules to permit traffic between EC2 and RDS.
- Re-test the form submission and verify data is inserted into the database.
- Amazon EC2 documentation
- EC2 Instance Connect
- Flask documentation
- AWS RDS documentation
- Python virtual environments (venv)