Deploying a Todo App on AWS ECS with ECR: A Step-by-Step Guide
Day 85: Deploying a Web App on AWS ECS with ECR
Table of contents
- Introduction
- Step 1: Set Up an EC2 Instance
- Step 2: Clone the Todo App Repository
- Step 3: Set Up ECR Repository
- Step 4: Install Docker and AWS CLI on EC2 Instance
- Step 5: Authenticate Docker with ECR
- Step 6: Build and Push Docker Image to ECR
- Step 7: Create ECS Cluster
- Step 8: Create Task Definition and Deploy
- Step 9: Check the App
- Conclusion
Introduction
In the ever-evolving landscape of cloud computing, deploying applications has become more efficient and scalable. Amazon Web Services (AWS) offers a suite of services that enable developers to deploy and manage applications with ease. In this 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
To get started, you'll need to launch an EC2 instance.
Launch an EC2 Instance:
- Use the AWS Management Console to 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
Once you're connected to your EC2 instance, clone your Todo app repository.
Clone the Repository:
git clone https://github.com/your-username/todo-app.git
cd todo-app
Step 3: Set Up ECR Repository
Next, we'll create an ECR repository to store our Docker image.
Navigate to ECR in the AWS Management Console:
Create a New Repository:
Name the repository
node-app
.
Step 4: Install Docker and AWS CLI on EC2 Instance
Install Docker and the AWS CLI to manage and deploy your application.
Install Docker and AWS CLI:
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
Authenticate your Docker client with your ECR registry to push your Docker images.
Authenticate Docker:
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 your ECR repository.
Build and Tag Docker Image:
docker build -t node-app . docker tag node-app:latest public.ecr.aws/u1o8l9k6/node-app:latest
Push Docker Image to ECR:
docker push public.ecr.aws/u1o8l9k6/node-app:latest
Step 7: Create ECS Cluster
Now, we’ll create an ECS cluster to run our application.
Navigate to ECS in the AWS Management Console:
Create a New Cluster:
Name the cluster
node-todo-cluster
.Choose Fargate as the launch type.
Step 8: Create Task Definition and Deploy
Define the tasks that will run on your ECS cluster.
Create a New Task Definition:
Name it
node-todo-app-task-definition
.Deploy the Task:
Select the task definition and click on "Deploy", then "Run Task".
Step 9: Check the App
Finally, ensure your application is running.
Get the Public IP of Your Fargate Instance
Open a Web Browser:
Navigate to
http://<public-ip>:8000
to check if the Todo app is running.
Conclusion
Congratulations! You've successfully deployed a Todo app on AWS ECS using ECR. This step-by-step guide covered setting up an EC2 instance, cloning the Todo app repository, configuring ECR, installing Docker and AWS CLI, building and pushing a Docker image, creating an ECS cluster, defining tasks, and finally deploying and checking the app. This workflow provides a scalable and efficient way to deploy containerized applications on AWS.
Happy Learning!
Follow me on LinkedIn.