DevOps (Day-85): Project-6 Utilizing AWS ECS Fargate and ECR with a Node JS app

DevOps (Day-85): Project-6 Utilizing AWS ECS Fargate and ECR with a Node JS app

Day 85: #90DaysOfDevOpsChallenge

ยท

6 min read

Dear Learners In Today Article we will explain the Deploying a Node JS app with the help of AWS ECS Fargate and AWS ECR.

Aim:-

The Project involves deploying a Node JS app on AWS ECS Fargate and AWS ECR.

Pre-requisite:-

Cloning the Source code form GitHub.

1 Let's go to the GitHub repository and copy the source code URL.

No alt text provided for this image

Cloning the Source code form GitHub Diagram

2 Create an EC2 instance in AWS Management console Navigate to the EC2 instance.

No alt text provided for this image

Create an EC2 instance in AWS Management console Navigate to the EC2 instance Diagram.

3 Clone the repository from GitHub to the EC2 instance.

No alt text provided for this image

Clone the repository from GitHub to the EC2 instance Diagram.

4 Navigate to AWS ECR.

No alt text provided for this image

Navigate to AWS ECR Diagra.

5 Create a repository, I have selected the Public repository and the repo name.

No alt text provided for this image

Create a repository, I have selected the Public repository and the repo name Diagram.

6 Select all the operating system versions according to the OS of Fargate you would select. Finally create the repository.

No alt text provided for this image

Select all the operating system versions according to the OS of Fargate you would select. Finally create the repository Diagram

No alt text provided for this image

Select all the operating system versions according to the OS of Fargate you would select. Finally create the repository Diagram

7 Now you can check the Public repository for the created repository.

No alt text provided for this image

Now you can check the Public repository for the created repository Diagram.

Configuring IAM

8 Create an IAM user in the AWS Management console.

No alt text provided for this image

Create an IAM user in the AWS Management console Diagram.

9 Attach the policies required for accessing the ECR.

No alt text provided for this image

Attach the policies required for accessing the ECR Diagram.

10 Install the awscli in the AWS EC2 instance.

No alt text provided for this image

Install the awscli in the AWS EC2 instance Diagram.

11 Connect the EC2 instance with AWS management console through awscli.

No alt text provided for this image

Connect the EC2 instance with AWS management console through awscli Diagram.

Push the image to ECR

12 Navigating to the AWS ECR and view the push commands Earlier we had pushed the image to DockerHub in my previous blogs. The steps and concepts are similar but the platform differs. Generally in IT industry ECR is used as an image registry.

No alt text provided for this image

Push the image to ECR Diagram.

Execute commands 1 and 2 in the EC2 instance.

Command1 : This will take the ecr token and provide to docker for the connection to the repository.

Command2: This will build the image from the Docker file.

No alt text provided for this image

Command1 : This will take the ecr token and provide to docker for the connection to the repository Diagram.

No alt text provided for this image

Command1 : This will take the ecr token and provide to docker for the connection to the repository Diagram.

14 Execute commands 3 and 4 in EC2 instance.

Command 3 : This tags the image that we have built using docker.

Command 4 :This command will push the image form EC2 instance to ECR.

No alt text provided for this image

Execute commands 3 and 4 in EC2 instance Diagram.

15 After the image push, you can check the ECR for the image.

No alt text provided for this image

After the image push, you can check the ECR for the image Diagram.

Configuring the AWS ECS

16 Navigate to the ECS repository in the AWS console.

No alt text provided for this image

Navigate to the ECS repository in the AWS console Diagram.

17 Create a cluster in ECS.

No alt text provided for this image

Create a cluster in ECS

18 Provide the cluster name,VPC and Subnet you want your application to be avaliable on.

No alt text provided for this image

Provide the cluster name,VPC and Subnet you want your application to be avaliable on Diagram.

Using AWS Fargate

One of the Major disadvantage of using AWS EC2 for an application is we have to create multiple instance in case of an application load increase that will have a cost impact.

To avoid this, we will use AWS Fargate which is a Serverless technique of providing the specification of applications that will be automatically managed without spinning off any instance.

1 Therefore, we will select AWS Fargate for the cluster to run on.

No alt text provided for this image

Therefore, we will select AWS Fargate for the cluster to run on Diagram.

2 The Cluster is now ready !!!

No alt text provided for this image

3 We used to run docker run to create a container in the EC2 instance out of the docker image. That was nothing but a task. Therefore let's create a task definition for our cluster.

No alt text provided for this image

We used to run docker run to create a container in the EC2 instance out of the docker image. That was nothing but a task. Therefore let's create a Di

4 Provide the task name, Container image details and ports for the application to be run on. We must have exposed a port in our Dockerfile.

No alt text provided for this image

Provide the task name, Container image details and ports for the application to be run on. We must have exposed a port in our Dockerfile Diagram.

5 Select the CPU and memory configuration according to the application load.

No alt text provided for this image

Select the CPU and memory configuration according to the application load Diagram.

6 Let the rest be default and click on next.

No alt text provided for this image

Let the rest be default and click on next Diagram.

7 Review the details and create the task.

No alt text provided for this image

Review the details and create the task Diagram.

8 Now, the task is finally created !!!!

9 Click on deploy and then Run task to run the task on the cluster we had crated.

No alt text provided for this image

Click on deploy and then Run task to run the task on the cluster we had crated Diagram.

10 Choose the cluster, Select the launch type to be Fargate.

No alt text provided for this image

Choose the cluster, Select the launch type to be Fargate Diagram.

11 Now Click to create.

No alt text provided for this image

Now Click to create Diagram.

12 The task is now deployed to the cluster.

No alt text provided for this image

The task is now deployed to the cluster Diagram.

Open Port in the security Group.

13 Navigate to the ENI ID in the task.

No alt text provided for this image

Navigate to the ENI ID in the task Diagram.

14 Go to the security group URL.

15 Navigate to the Inbound rule in the security group and open the Port 80 which is HTTP and select my IP to have access for myself.

Project Live Execution

16 Navigate to the task that we created. Take the Public IP.

17 We can see our application is live !!!!!!!!!!!

Thank you for reading!! Hope you find this helpful.

#day85challenge#90daysofdevops

Always open to suggestions..!!

~ Manoj Bhamidipati ๐Ÿ™‚

Next Topic

Day 86: Deploying a Portfolio app on AWS S3 Bucket using GitHub.

ย