Skip to main content

Command Palette

Search for a command to run...

Project 5: Deploy Web-App to ECS (fargate) using CodeBuild & CodePipeline

#90daysofdevops

Published
5 min read
Project 5: Deploy Web-App to ECS (fargate) using CodeBuild & CodePipeline
V

I'm proficient in a variety of DevOps technologies, including AWS, Linux, Python, Docker, Git/Github, Shell Scripting, Jenkins and Computer Networking. My greatest strength is the ability to learn new things because I believe there is always room for self-development

🚀 Introduction

In this project, I automated the deployment of a web application to Amazon ECS (Fargate) using AWS CodeBuild and CodePipeline. By leveraging these services, I was able to set up a complete CI/CD workflow where every code push triggers an automated build and deployment — without managing any servers. This approach ensures faster releases, consistent deployments, and a fully scalable infrastructure with minimal manual intervention.


🔸Step 1: Launch EC2 instance, Download AWS CLI & Docker

  • Add security group port 3000 to ec2
#For Downloading AWS CLI follow below commands
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install

#check version
aws --version
#For Downloading Docker follow below command
sudo apt update && sudo apt install docker.io -y

#check version
docker --version

#run docker without sudo
sudo usermod -aG docker $USER

🔸Step 2: Clone repo in EC2

git clone https://github.com/VisheshGhule/Nodejs-SSL-Server.git

🔸Step 3: Build docker image

cd Nodejs-SSL-Server

#build docker image
 docker build -t nodejs-server-demo .

#run a container on port 3000
docker run -dp 3000:3000 nodejs-server-demo

#run below on browser
http://<public-ip>:3000


🔸Step 4: Create AWS CLI User

  • Create IAM user & attach policies AmazonEC2ContainerRegistryFullAccess

  • After creating user click on that User name & come in Security credentials and Create access key

  • Follow as it is steps as shown in below picture

  • Then do aws configure in ec2


🔸Step 5: Create ECR repo

  • After creating ECR repo, push image into it. Follow as it is steps as shown in below picture.

  • Click on view push command and copy-paste that code in ec2. This command will push docker image to ECR repo

  • Image has successfully pushed to ECR.


🔸Step 6: Create Security Group

  • In EC2 dashboard there is option of SG to create it.

  • Add inbound rule 80 for ALB

  • Create another SG for ECS. Add inbound rule 3000 & in source select SG that we have created earlier (above SG). Follow given picture as it is as shown in below picture


🔸Step 7: Create Cluster in ECS (fargate)

  • Follow steps as it is as shown in below picture to create cluster


🔸Step 8: Create Task Defination

  • Follow as it is steps as shown in below picture to create task defination & remaining keep as default

  • In container copy-paste ECR image URI & in port mapping write 3000 container port. Follow below picture as it is shown in below picture

  • Keep resource allocation limits default as shown in below picture. And now click on create task defination


🔸Step 9: Create Service in cluster

  • Follow as it is shown in below picture to create service

  • Select launch type Fargate

  • Under Networking section follow as it is steps as shown in below picture

  • Create Load balancer after networking section & follow as it is steps as shown in below picture.

  • Here our service & tasks is active & running successfully


  • After service & tasks running successfully. Now go in load balancer select that load balancer → in action → edit SG → & attach SG that we have created earlier for ALB. Follow below picture to understand it in better way

  • After attaching SG, open that load balancer and copy-paste DNS name on browser

  • In health and metrics in health target we can see that it is healthy & also on right side there is logs.


🔸Step 10: Create CodeBuild

  • Follow as it is steps as shown in below picture to create codebuild

  • In credential, below runner provider connect your github acoount. I have already connected

  • And follow steps as it is

  • After creating codebuild under project details, come under environment section and click on that service role and attach role AmazonEC2ContainerRegistryFullAccess . Follow as shown in below picture.


🔸Step 11: Create CodePipeline

  • Follow as it is steps as shown in below picture to create pipeline

  • In source select github and in connection select your repo but before that first you have to connect to github. I have already connected

  • Its is environment variables it is optional.

  • You can get container name in ECS → Cluster → click on cluster → click on service → go in tasks → select tasks → there you will get container name as shown in below picture

  • Skip test stage

  • Final Step now do deployment

  • Follow below picture as it is to do deployment

  • CodePipeline is successfully created


🔸Step 12: Check CI/CD pipeline to AWS ECS

  • In github html file i have made some changes lets see cicd working properly or not

  • CI/CD is working good. In github i made changes in title Scale-Up-SaaS → Scale-Up-SaaS v.2. And in below picture you can see ci-cd is wroking


🚀Conclusion

By integrating ECS (Fargate) with CodeBuild and CodePipeline, I built a serverless container deployment pipeline that is both efficient and production-ready. This setup not only eliminates the hassle of managing infrastructure but also makes deployments repeatable, reliable, and quick. Moving forward, this workflow can easily be extended with monitoring, blue/green deployments, and security scans to make it even more robust. With the right automation in place, delivering high-quality applications becomes a smooth, streamlined process.


Thanks for reading to the end; I hope you gained some knowledge.❤️🙌

Linkedln

Twitter

Github

Project 5: Deploy Web-App to ECS (fargate) using CodeBuild & CodePipeline