Mastering AWS DevOps with AWS Fargate Architecture: Leveraging ECR, ECS, and Load Balancer

Nirmalya Saha
5 min readMay 12, 2024

--

AWS Fargate stands out as a powerful solution for running containerized workloads without the need to manage underlying infrastructure. By leveraging Fargate in conjunction with AWS services like Elastic Container Registry (ECR), Elastic Container Service (ECS), and Load Balancer, teams can achieve a streamlined DevOps workflow that accelerates development cycles and enhances application resilience.

Introduction

Welcome to the exciting world of AWS DevOps management! If you’re a beginner AWS software engineer eager to take your first steps in the DevOps world you’re in the right place.

In this step-by-step guide, we’ll navigate the AWS services to containerize a node.js server in AWS ECR and deploy the containerized image in AWS ECS with serverless Fargate architecture auto scaled using a Load Balancer.

FARGATE ARCHITECTURE

Why These Services?

Before we dive into deployment, let’s understand why I’ve chosen these particular AWS services.

  1. AWS ECR (Elastic Container Registry): Securely store, manage, and deploy Docker container images.
  2. AWS ECS (Elastic Container Service): Orchestrate and manage Docker containers at scale.
  3. AWS LOAD BALANCER that will manage and route traffic to our ECS Service Tasks.
  4. AWS Fargate: Run containerized applications without managing servers.

Assumptions

  • A node.js server project hosted in a git repository on a service such as Bitbucket or GitHub.
  • AWS account, docker and node.js with npm installed in your system.

Containerize your application in AWS ECR

Create repository
  1. Go to AWS ECR console and click “Create repository”.
  2. Select private repository.
  3. Enter the repository name of your choice and click create.
  4. Dockerise your application: In order to make a docker image of your application we need to have a dockerfile inside it. Create one according to your application environment.
  5. From console click “Push commands”.
  6. Run all the push commands you will get your server’s dockerised image pushed.
AWS ECR image

Create your ECS cluster

Now lets jump into setting up the ECS. ECS has four major components as shown in the picture below.

ECS architecture
  1. Container Definition: In this, we specify the image to be used. The one we pushed into the ECR.
  2. Task Definition: Task is nothing but a running instance of your container. In its definition, we specify the memory and number of CPUs to allocate to the task.
  3. Service: It serves as the environment for your tasks e.g vpc, subnets, security groups.
  4. Cluster: It’s a container for your ECS services, one cluster can have multiple services.
Create ECS cluster
  1. From AWS ECS cluster console click “Create”.
  2. Provide your cluster name and select infrastructure as AWS Fargate.

Create your Task Definition

Create Task Definition
  1. Go to the Task Definitions tab and click on Create.
  2. Provide your task definition family name and infrastructure as AWS Fargate.
Task Definition infrastructure
  1. Select launch type as AWS Fargate.
  2. Choose your desired operating system and system requirements.
  3. You can provide permissions via Task role.
Task Definition Container
  1. Provide your containerized image deployed in AWS ECR, the name and image uri.
  2. Provide your server port mappings and system requirements
Task Definition Health Check

This is optional step for providing your health check information.

Create your cluster service

ECS Service

Go to the clusters tab and select your newly created cluster and under the Services sub-tab, click on Create.

Create Service

Select environment as Capacity provider strategy and rest as default.

Service Deployment
  1. Select application type as Service.
  2. Select the task definition that you created earlier from the dropdown.
  3. Provide a name to your service and the number of tasks you want to be running at all times. In our case, I have given the value 2.
Service Networking

Specify the VPC and subnets keeping the below point in mind is that the public subnets of load balancer and private subnets of ECS tasks should be in same availability zones. Otherwise your load balancer wont be able to access the ECS tasks and your tasks would be stopping/starting continuously.

Service Load Balancer
  1. Select Application Load Balancer from the dropdown.
  2. Provide the container and target group name with your health check route. Remember to put the listener to port 80 and rest keep default.
Service Auto Scaling
  1. Optionally you can also set auto scaling.
  2. Provide your minimum and maximum task number you want to run.
  3. Select your policy type and scaling threshold and click on Create.

We are all set your app should be running fine now. Hit the DNS name of your load balancer in the browser and your app should be working fine.

--

--

Nirmalya Saha
Nirmalya Saha

Written by Nirmalya Saha

SDE @Delta-V Analytics | Formerly @GFG, @LGM, @SSB | FullStack DevOps-AWS, Blockchain, Android Developer | Transforming lives through tech innovation

No responses yet