In this blog post, I’ll walk you through how I successfully deployed my URL Shortener app using AWS EC2, and how I laid the foundation for high availability by preparing for Auto Scaling Groups (ASG) and Load Balancers.
Step 1: Prepare Your Application
My project is a URL Shortener App. Before deploying, I did the following:
- Created a GitHub repository for the project.
- Ensured the app runs locally using Flask (or your framework of choice).
- Prepared requirements.txt for Python dependencies.
- Check my Repo if Needed.
Step 2: Launch an EC2 Instance
- Go to the AWS EC2 Dashboard.
- Click on "Launch Instance".
- Choose:
- Amazon Linux 2 or Ubuntu
- Instance type: t2.micro (free tier eligible)
- Under Key pair, create a new key pair or select an existing one and download the .pem file.
- Create a Security Group:
- Port 22 (SSH) → 0.0.0.0/0
- Port 80 (HTTP/frontend) → 0.0.0.0/0
- Port 5000 (Flask backend) → 0.0.0.0/0
- Launch the instance!
Step 3: Connect to Your EC2 via SSH
Using Git Bash or terminal:
ssh -i your-key.pem ec2-user@<your-ec2-public-ip>
- Replace <your-key.pem> with your downloaded key and with your instance’s IP.
Step 4: Set Up and Run Your App on EC2
- inside your EC2 terminal:
# Update and install Git + Python
sudo yum update -y
sudo yum install git python3 -y
# Clone your GitHub repo
git clone https://github.com/yourusername/your-repo.git
cd your-repo
# Install dependencies
pip3 install -r requirements.txt
# Run the app
python3 app.py
- If your Flask app runs on port 5000, you should now be able to access it at:
http://<your-ec2-public-ip>:5000
Step 5: Create an AMI (Amazon Machine Image)
To use the current EC2 setup for Auto Scaling:
- Go to EC2 > Instances.
- Select your running instance.
- Click Actions > Image > Create Image.
- Name it url-shortener-ami and save.
Step 6: Create a Launch Template
- Go to EC2 > Launch Templates.
- Click Create Launch Template.
- Fill in:
- Name: url-shortener-template
- Choose the AMI you just created
- Select instance type (e.g., t2.micro)
- Create the template.
Step 7: Create an Auto Scaling Group (ASG)
- Go to EC2 > Auto Scaling > Auto Scaling Groups.
- Click Create Auto Scaling Group.
- Choose your Launch Template.
- Set:
- Group size: e.g., min: 1, max: 3
- VPC + subnets
Step 8:Attach a Load Balancer
- Create a Target Group first (protocol: HTTP, port: 80)
- Register instances with the target group
- Use Application Load Balancer (ALB)
- Configure health checks and scaling policies.
- Review and create the ASG.
Step 9:Test Everything:
- Check the EC2 Instance with it's Public IP weather our app can accessible.
- Check the ALB using Its DNS Name weather it balancing the load.
- Check the Health of ASG and also it shows(in - service)
Step 10:
For saving cost and doing all these within Free tier:
- Stop the EC2 Instances After the work has been Completed.
- Delete the ASG and Load Balancer to avoid Charges.
- Un register the AMI and Snapshot and Launch Templates to avoid additional Payments.
What we Learned:
- How EC2 works and how to SSH into it
- Flask app deployment to the cloud
- Why and how we use AMI, Launch Template, ASG, and ALB
- Basic cloud scalability setup for real-world use
Future Plans:
- Adding HTTPS with SSL using ACM
- connect domain name via Route 53
- Setting up Docker and Deploy containers
Top comments (2)
Good step-by-step guide!
@akashabish, The blog looks awesome and insightful