AWS Builder Center

Deploying a Containerized Application on AWS Fargate: My Hands-on Experience with ECS

In this article, I share my experience deploying a containerized application using Amazon ECS and AWS Fargate. From building Docker images and pushing them to Amazon ECR to configuring private subnets, load balancing, auto scaling, and CI/CD, here's how I built a scalable AWS deployment architecture for my TalentFlow AI project.

Deploying a Containerized Application on AWS Fargate: My Hands-on Experience with ECS

Introduction

Containerization has changed how applications are packaged, deployed, and managed. Docker makes it possible to package an application and its dependencies into a portable image. However, running containers in production introduces another challenge: managing the infrastructure behind them.
For my AWS Cloud Internship capstone project, TalentFlow AI, I wanted to deploy a containerized application without having to provision and maintain EC2 instances manually.
That's where Amazon ECS and AWS Fargate came into the picture.
In this article, I'll walk through how I used AWS Fargate to deploy my application, the architecture I implemented, and some of the challenges I encountered during the process.

1. Understanding the Project

TalentFlow AI is a recruitment dashboard backed by a Flask API and AWS services.
The original application was a static frontend built with HTML, CSS, and JavaScript. My task was to build the cloud infrastructure behind it.
The deployment included:
  • Docker for containerization.
  • Amazon ECR for storing container images.
  • Amazon ECS with AWS Fargate for running containers.
  • Application Load Balancer for distributing incoming traffic.
  • Amazon DynamoDB for persistent data storage.
  • Amazon CloudFront and private Amazon S3 for frontend delivery.
  • AWS CloudWatch for monitoring.
  • AWS CodePipeline and CodeBuild for CI/CD.
  • Terraform for infrastructure as code.

2. Why I Chose AWS Fargate

Amazon ECS provides container orchestration, while AWS Fargate provides serverless compute capacity for running containers.
Traditionally, running containers on ECS with EC2 requires managing the underlying instances, including capacity, operating system updates, and infrastructure maintenance.
With Fargate, I didn't need to provision or manage EC2 instances for my container workloads.
Some reasons I chose Fargate were:
  • No need to manage underlying servers.
  • Integration with Amazon ECS.
  • Support for task-level CPU and memory configuration.
  • Integration with Application Load Balancers.
  • Support for service auto scaling.
  • Easier infrastructure management for my application.
Fargate allowed me to focus more on the application deployment rather than managing the compute infrastructure.

3. Understanding the Architecture

The deployment architecture followed this flow:
GitHub → CodePipeline → CodeBuild → Amazon ECR → Amazon ECS → AWS Fargate
Here's how the components worked together:
  1. I pushed application changes to GitHub.
  1. AWS CodePipeline triggered the deployment pipeline.
  1. CodeBuild built the Docker image using the Dockerfile.
  1. The image was tagged using the Git commit ID.
  1. The image was pushed to Amazon ECR.
  1. The ECS service deployed the updated container image using Fargate.
  1. The Application Load Balancer routed incoming application traffic to healthy Fargate tasks.
The ECS Fargate tasks ran inside private subnets across two Availability Zones.
The Application Load Balancer was placed in public subnets, while the application containers were not directly exposed to the internet.

4. Containerizing the Application with Docker

Before deploying the application, I packaged the Flask backend and frontend into a Docker image.
I used a Dockerfile based on Python 3.12 slim and Gunicorn to serve the Flask application on port 8000.
The application included a health endpoint:
 /health 
This endpoint was used by the Application Load Balancer to check whether the application was healthy.
The basic Docker workflow was:
docker build -t talentflow-ai .
To test the container locally:
docker run -p 8000:8000 \
-e AWS_DEFAULT_REGION=us-east-1 \
talentflow-ai
Once the container worked locally, the next step was publishing the image to Amazon ECR.

5. Deploying Containers Using Amazon ECS and Fargate

After pushing the Docker image to ECR, I configured the ECS service to run the application using Fargate.
The important components were:
ECS Cluster: Provided the logical environment for running container workloads.
Task Definition: Defined the container image, CPU and memory configuration, port mappings, and task settings.
Fargate Tasks: Ran the application containers without requiring me to manage EC2 instances.
ECS Service: Maintained the desired number of running tasks and managed deployments.
I configured the tasks to run in private subnets without public IP addresses.
The ECS security group allowed traffic on port 8000 only from the Application Load Balancer's security group.
This helped keep the application containers isolated from direct internet access.

6. Configuring Auto Scaling

Deploying an application is only one part of the process. It should also be able to respond to changing workloads.
For TalentFlow AI, I configured ECS service target tracking auto scaling based on average CPU utilization.
The configuration was:
  • Minimum tasks: 1
  • Maximum tasks: 3
  • Target CPU utilization: 50%
During testing, I temporarily lowered the CPU target to 5% to demonstrate the scaling mechanism.
The service scaled from one task to three tasks under the test workload and returned to one task after the load stopped.
This helped me understand how ECS service auto scaling works with Fargate.

7. Automating Deployment with CI/CD

Manually building and deploying containers every time code changes would be repetitive.
To automate this process, I implemented a CI/CD pipeline using AWS CodePipeline and CodeBuild.
The workflow was:
  1. Push code changes to the main branch in GitHub.
  1. CodePipeline detects the source change.
  1. CodeBuild authenticates with Amazon ECR.
  1. Docker builds the application image.
  1. The image is tagged with the Git commit ID.
  1. CodeBuild pushes the image to ECR.
  1. The deployment stage updates the ECS service.
I used an ECS rolling deployment strategy to update the application.
This made the deployment process more consistent and reduced manual intervention.

8. Challenges I Faced

Working with AWS services also meant troubleshooting real infrastructure problems.
Here are some issues I encountered:
1. Private subnet routing issue
After rebuilding the NAT gateway and Application Load Balancer, the API started returning errors.
After investigating the route table, I found that the private route still pointed to a deleted NAT gateway, resulting in a blackhole route.
I corrected the route to point to the new NAT gateway.
2. CI/CD deployment failure
The CodePipeline deployment stage initially failed because the pipeline role did not have the required ECS permissions.
I resolved this by adding the necessary ECS permissions and  iam:PassRole  access for the ECS roles.
3. Auto scaling not triggering
During the initial load tests, CPU utilization remained low because the workload was limited by DynamoDB capacity and network latency.
I temporarily lowered the CPU target to verify that the scaling mechanism worked.
These troubleshooting experiences helped me understand that successful cloud deployment depends on networking, IAM permissions, application performance, and monitoring working together.

9. Results and Testing

I performed load testing using Apache Bench to understand how the application behaved under concurrent requests.
Some observations from my tests:
  • The  /health  endpoint handled 31,817 requests at approximately 75.75 requests per second with zero failed requests in one test.
  • With the CPU scaling target temporarily lowered to 5%, the service scaled from one to three tasks.
  • The scaling test handled 64,111 requests at approximately 152.64 requests per second with zero failed requests.
  • The ECS service returned to one task after the load stopped.
These results were from my project test environment and should not be treated as a general Fargate performance benchmark.

10. What I Learned

This project gave me practical exposure to several important cloud engineering concepts:
  • Containerizing applications using Docker.
  • Understanding the relationship between ECS, Fargate, and ECR.
  • Deploying containers inside private subnets.
  • Configuring Application Load Balancer health checks.
  • Implementing ECS service auto scaling.
  • Automating deployments with CodePipeline and CodeBuild.
  • Troubleshooting IAM and networking issues.
  • Monitoring infrastructure and managing AWS costs.
Most importantly, I learned that deploying a container is not just about building a Docker image. It also involves networking, security, scalability, monitoring, and automation.

Conclusion

Using AWS Fargate with Amazon ECS helped me deploy TalentFlow AI without managing the underlying EC2 infrastructure.
The project allowed me to connect multiple AWS services into a working deployment architecture and understand how containerized applications can be deployed and operated in the cloud.
I'm continuing to explore AWS services and improve my cloud engineering skills through hands-on projects.
Thanks for reading!
Happy Building! 🚀
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article