Day 85: Deploying a Web App on AWS ECS with ECR (Feb 19, 2024)

Hey there! I'm currently working as an Associate DevOps Engineer, and I'm diving into popular DevOps tools like Azure Devops,Linux, Docker, Kubernetes,Terraform and Ansible. I'm also on the learning track with AWS certifications to amp up my cloud game. If you're into tech collaborations and exploring new horizons, let's connect!
Introduction
In the world of cloud computing, deploying applications has become more efficient and scalable. Amazon Web Services (AWS) provides a range of services that enable developers to easily deploy and manage their applications. In this step-by-step guide, we'll walk through the process of deploying a Todo app on AWS ECS (Elastic Container Service) using ECR (Elastic Container Registry). This tutorial assumes you have a basic understanding of AWS services and have an AWS account.
Step 1: Set Up an EC2 Instance
Launch an EC2 instance with Amazon Linux or any other suitable Amazon Machine Image (AMI).
SSH into the instance.
ssh -i your-key.pem ec2-user@your-instance-ip
Step 2: Clone the Todo App Repository
Clone the Todo app repository from your version control system (e.g., GitHub).
git clone https://github.com/your-username/todo-app.git
cd todo-app
Step 3: Set Up ECR Repository
Navigate to the AWS Management Console and open the Elastic Container Registry (ECR).
Create a new repository named
node-app.

Step 4: Install Docker and AWS CLI on EC2 Instance
Install Docker and the AWS CLI on your EC2 instance.
sudo apt update -y
sudo apt install docker.io
sudo usermod -a -G docker ubuntu
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Step 5: Authenticate Docker with ECR
Run the following command to retrieve an authentication token and authenticate your Docker client with your ECR registry.
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/u1o8l9k6
Step 6: Build and Push Docker Image to ECR
Build your Docker image and push it to the ECR repository.
docker build -t node-app .
docker tag node-app:latest public.ecr.aws/u1o8l9k6/node-app:latest
docker push public.ecr.aws/u1o8l9k6/node-app:latest
Step 7: Create ECS Cluster
Navigate to ECS in the AWS Management Console.
Create a new cluster named
node-todo-cluster.Choose Fargate as the launch type.

Step 8: Create Task Definition and Deploy
Create a new task definition named
node-todo-app-task-definition.Select the task definition and click on "Deploy," then "Run Task."


Step 9: Check the App
Once the task is running, note the public IP of your Fargate instance.
Open a web browser and navigate to
<public-ip>:8000to check if the Todo app is running.






