DEV Community

Ashwin Venkatesan
Ashwin Venkatesan

Posted on

Deploying A Flask App on AWS ECS with Real-time CloudWatch Monitoring πŸ“Š


πŸš€ 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.

  1. Give your Cluster a name – in my case I'm naming ECS-FLASK-APP-Cluster

  2. We dont need to touch other settings Leave as default and click Create.

  3. 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.

  • Go to your ECS Cluster --> click Create Service

  • Select your Task Definition and Revision (the one you created in the previous step).

  • Give the service a name.

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.

  1. Now it’s time to verify that your Flask app is live.
  2. In your ECS Cluster, go to the Tasks tab under your service.
  3. You’ll see one or more running tasks β€” click on the Task ID.
  4. Scroll down to the **Networking **section.
  5. 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.

  1. Go to the Amazon CloudWatch Console β†’ click Dashboards β†’ Create dashboard.
  2. Give your dashboard a name (Ecs-flask-dashboard).

  1. Choose a widget type (like Line, Stacked Area, or Number) depending on what metric you want to display.
  2. Click Add widget and select the ECS / Fargate metrics you want to track β€” for example:

CPU Utilization
Memory Utilization

  1. After the required settings and customizing Save the dashboard.

  2. 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)