Deploying Python Web App on AWS ECS with Fargate and ALB

Deploying Python Web App on AWS ECS with Fargate and ALB

Introduction

As we start the journey of deploying a Python web application using AWS ECS with Fargate and ALB, we'll explore the closer look at how to handle containerized environments in the AWS cloud. In this blog post, we'll guide you through the step-by-step process, ensuring a seamless deployment that combines the simplicity of ECS, the flexibility of Fargate, and the efficiency of ALB. Let's empower your Python web app for success in a scalable and reliable cloud environment

Pre-requisites

  • AWS free tier Account

  • Github Account

Step 1: Fork and Clone the Repository

Fork the repository https://github.com/msnehabawane/flask-calculator-demo.git

Clone the forked repository to your local machine using git clone .

Step 2 : Create a new Repository in AWS ECR

Go to the AWS Console and search for ECR

Create a public repository.

Here we created our repository.

Step 3 : Push Image To ECR

Go inside the repository flask-app-repo and click on view push command

Run the below commands one by one on your local machine (VS Code)

first command will Authenticate Docker with ECR Public

aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/y0b9h4w0

Second command is Build Docker Image

docker build -t flask-app-repo .

Tag Image

docker tag flask-app-repo:latest public.ecr.aws/y0b9h4w0/flask-app-repo:latest

Push Image to ECR

docker push public.ecr.aws/y0b9h4w0/flask-app-repo:latest

Here we successfully push the image on AWS ECR

Go inside the repository then click on the image we pushed and copy the URL

Copy that URL

We need this URL during creation of task defination

public.ecr.aws/y0b9h4w0/flask-app-repo:latest

Step 4 :Create an ECS Cluster

Go to the ECS service console follow the below instructions and create cluster.

Step 5 : Define a Task Definition for Python

Here we created task defination successfully

Step 6 : Create ECS Service for Python using Fargate with ALB

Inside a cluster create ECS service

Step 7 :Access Python through ALB

Find the DNS of your ALB:

Once the service is running, go to the AWS Management Console, navigate to EC2, and then "Load Balancers.

Find your ALB, and note its DNS name.

python-web-lb-1457053112.ap-south-1.elb.amazonaws.com

Access Python:

Open a web browser and go to the ALB's DNS name (e.g., http://your-alb-dns-name).

You should see the default Python Demo Application.

Congratulations!!

We Successfully Deployed Python Web App using AWS ECS with Fargate and ALB

Grateful for each reader of my blog—your support means the world! Excited to keep sharing and growing together. Thank you! 🙏 #Gratitude

Neha Bawane