π Want to see your Flask app live on AWS ECS within 15 minutes β with real-time monitoring dashboards? π₯
In this walkthrough, weβll take a Dockerized Flask application (already uploaded to Amazon ECR/ you can also upload to Dockerhub) and deploy it on AWS ECS (Fargate).
Once deployed, weβll integrate Amazon CloudWatch to monitor key metrics like CPU and memory utilization, and even visualize them through a custom CloudWatch Dashboard.
By the end of this tutorial, youβll have a fully managed, scalable, and monitored Flask app running seamlessly on AWS.
βοΈ Tech Stack & AWS Services Used
Before we dive in, hereβs a quick look at the tools and services powering this project:
- Flask β Python-based lightweight web framework for the application.
- Docker β To containerize the Flask app.
- Amazon ECR (Elastic Container Registry) β To store and manage Docker images.
- Amazon ECS (Elastic Container Service) β To deploy and run the containerized Flask app.
- AWS Fargate β Serverless compute engine for running containers without managing EC2 instances.
- Amazon CloudWatch β To collect metrics, monitor container performance, and visualize data using dashboards.
Let's Get Started:
Step 1:Create an ECS Cluster:
1.Navigate to Aws ECS on AWS Console
2.Now we need to create Cluster.
Give your Cluster a name β in my case I'm naming ECS-FLASK-APP-Cluster
We dont need to touch other settings Leave as default and click Create.
Wait for few minutes until our cluster gets created. And after few minutes you will see an success message.
Step 2: Create a Task Definition
Now our Cluster is ready. We need to create a Task Definition
-- it is basically a blueprint which tells ECS which container to run, how much memory and CPU to allocate and what kind of networking to use.
- In the ECS Console, go to Task Defintions --> Click Create new Task definition
- Give a name for the task definition family.
Next, choose the Launch type as Fargate(it is serverless compute engine for containers, as we need not to Manage the servers ourselves).
Under the Container section, click Add container
Enter the name for your container.
In the Image URI field, paste the image URL from your Amazon ECR repository(you can also use external container repositories like DockerHub, I'm going with ECR).
Select the port 5000 as our Flask app is exposed on port 5000.
Allocate the required CPU/memory based on your app needs (I'm going with 512M CPU and 1GB memory).
Click Add, Then wait for few Minutes and save your Task defintion.
STEP 3: Create an ECS Service
Now our Task Definition is ready, it's time to create a Service This tells how many copies of your app (tasks) of our container to run and keeps them running if other containers fail.
Select your Task Definition and Revision (the one you created in the previous step).
Under the Launch type, choose Fargate.
- Under Networking, choose your VPC and subnets, and enable Auto-assign public IP if you want to access the app publicly.
- Create a Security Group and allow port*Port 5000* inbound, Which is very important.
- Review all configurations, then Click Create Service.
- Wait for a few moments, and you will have the service created.
π Step 4: Access the Flask App
Once the service is up and running, ECS automatically launches your container on AWS Fargate.
- Now itβs time to verify that your Flask app is live.
- In your ECS Cluster, go to the Tasks tab under your service.
- Youβll see one or more running tasks β click on the Task ID.
- Scroll down to the **Networking **section.
- Under Network bindings, youβll find the public IP address assigned to your running container.
- Copy that IP and open it in your browser
π Congratulations β Your Flask App is Live!
Awesome work! Your Flask application is now successfully deployed on AWS ECS using Fargate π
- Now that your app is live, letβs move to the next part β monitoring and observability.
Step 5: Create a CloudWatch Dashboard
To monitor your Flask appβs performance in real-time, weβll start by creating a CloudWatch Dashboard. This dashboard will give you a single view of all the important metrics for your ECS service and container.
- Go to the Amazon CloudWatch Console β click Dashboards β Create dashboard.
- Give your dashboard a name (Ecs-flask-dashboard).
- Choose a widget type (like Line, Stacked Area, or Number) depending on what metric you want to display.
- Click Add widget and select the ECS / Fargate metrics you want to track β for example:
CPU Utilization
Memory Utilization
After the required settings and customizing Save the dashboard.
Here you can see the dashboard we have created; wait for a few minutes, and you can see the line flow as per the metrics.
π» Full Project Code
You can access the complete flask ECS project here:
GitHub Link: https://github.com/Imash24/ECS-FLASK-APP
β Conclusion
Congrats! Youβve successfully deployed a Flask application on AWS ECS using Fargate, and set up a CloudWatch dashboard to monitor its performance in real-time.
In this walkthrough, you learned how to:
- Use ECS Fargate to run containerized applications without managing servers.
- Deploy a Dockerized Flask app from ECR.
- Set up an ECS Service to keep your app running and scalable.
- Monitor key metrics like CPU, memory, and network traffic using CloudWatch Dashboards.
This project gives you a hands-on understanding of containerized deployments on AWS, and is a solid step toward mastering DevOps and cloud-native applications.
Top comments (0)