Deploying a 2-tier App on AWS ECS, ECR & Fargate:

Deploying a 2-tier App on AWS ECS, ECR & Fargate:

Key points:

Amazon ECR is a fully managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images.

Amazon ECR complements Amazon ECS and other container orchestration tools, providing a reliable and secure way to store and manage Docker container images in the AWS cloud environment.

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service provided by Amazon Web Services (AWS). It simplifies the deployment, management, and scaling of containerized applications using Docker containers.

AWS Fargate is a serverless compute engine for containers provided by Amazon Web Services (AWS). It allows you to run containers without managing the underlying infrastructure, making it easier to deploy and manage containerized applications. Fargate is part of the broader AWS ECS (Elastic Container Service) ecosystem, but it also integrates with Amazon EKS (Elastic Kubernetes Service).

Hands-On

Launch an EC2 instance (t2.micro):

  • Update the instance:

  • Clone the app repo:

https://github.com/LondheShubham153/node-todo-cicd.git

git clone https://github.com/LondheShubham153/node-todo-cicd.git

  • Installation of AWS CLI:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install -i /usr/local/aws-cli -b /usr/local/bin --update

  • Login on AWS-cli using IAM credentials:

Create a AWS managed public repo(ECR):

Steps for pushing the docker image(of application) to ECR:

Docker login :

aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/r5e4d8y9

Docker building :

Docker tagging :

docker tag nodejs-app:latest public.ecr.aws/r5e4d8y9/nodejs-app:latest

Docker push to ECR:

docker push public.ecr.aws/r5e4d8y9/nodejs-app:latest

We've successfully created an Amazon ECR repository and pushed a Docker image to it. Now use this image in ECS tasks.

Creation of Cluster:

This infrastructure creation can be viewed @ CloudFormation

Define task:

  • In ECS, a task is the fundamental unit of work and can consist of one or more containers. You need to define task definitions that specify how containers should run within a task.

  • Specify the Docker image, CPU and memory requirements, networking, and other settings.

Container configuration:

Task Run:

Accessing the deployed app after running the task:

Exposing the port of app :

Did you find this article valuable?

Support Santosh Chauhan's blog by becoming a sponsor. Any amount is appreciated!