AWS-Project:"Architected and Deployed Scalable Node.js Application on AWS ECS with ECR Integration"

AWS-Project:"Architected and Deployed Scalable Node.js Application on AWS ECS with ECR Integration"

Introduction

In this guide, we'll walk through the process of deploying a Node.js application on Amazon's ECS (Elastic Container Service) using the Elastic Container Registry (ECR). The steps include pulling the Node.js application code from GitHub on an EC2 instance, building a Docker image, pushing it to ECR, and finally deploying it on ECS.

Step 1: Setting Up the EC2 Instance

  • Create an EC2 instance on AWS.

  • Clone the Node.js application code from GitHub.

Step 2: Setting Up ECR

  • Create an ECR repository (e.g., node-app).

  • Install Docker on the EC2 instance

  • Let's Configure AWS:

Step 3: Configuring IAM Permissions

  • Add the necessary IAM permissions to the EC2 instance.

    • AmazonElasticContainerRegistryPublicFullAccess

    • AmazonElasticContainerRegistryPublicPowerUser

    • AmazonElasticContainerRegistryPublicReadOnly

Step 4: Pushing Docker Image to ECR

  • Authenticate Docker with ECR.
ubuntu@ip-172-31-46-128:~$ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/i0q9t8c3
WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
  • Build and push the Docker image.
ubuntu@ip-172-31-46-128:~/projects/node-todo-cicd$ docker build -t node-app .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon    382kB
Step 1/7 : FROM node:12.3-alpine
Step 2/7 : WORKDIR /app
 ---> Running in f17d15254844
Removing intermediate container f17d15254844
 ---> 9039d1467670
Step 3/7 : COPY . .
 ---> bae48e91e155
Step 4/7 : RUN npm install
 ---> Running in b7b2a8acc7dc
Step 7/7 : CMD ["node", "app.js"]
 ---> Running in 6e5897412b19
Removing intermediate container 6e5897412b19
 ---> 7f25664c2e5f
Successfully built 7f25664c2e5f
Successfully tagged node-app:latest
  • After the build is completed, tag your image so you can push the image to this repository:

  • Run the following command to push this image to your newly created AWS repository:

ubuntu@ip-172-31-46-128:~/projects/node-todo-cicd$ docker tag node-app:latest public.ecr.aws/i0q9t8c3/node-app:latest
ubuntu@ip-172-31-46-128:~/projects/node-todo-cicd$ docker push public.ecr.aws/i0q9t8c3/node-app:latest
The push refers to repository [public.ecr.aws/i0q9t8c3/node-app]
1300a0bb85e1: Pushed
c491c60309be: Pushed
4bc36e8b6cd7: Pushed
e8495224fb7c: Pushed
a5b3bec66fc4: Pushed
f5d042a13ed7: Pushed
f1b5933fe4b5: Pushed
latest: digest: sha256:ac14b87c3d4b6c66b18e03ea59a7d7f38f7eb925e6a49c92df2a14ad24e66102 size: 1785
ubuntu@ip-172-31-46-128:~/projects/node-todo-cicd$
  • Successfully Pushed the image:

Step 5: Deploying on ECS

  • Set up an ECS cluster and task definition.

  • Creating new task definition.

  • Let's run this task on EKS-Cluster: Name called-node-app-cluster1

  • Deploy the Node.js application on ECS using the Docker image from ECR. is now running: <publicip:8000>

Step 6: Monitoring with CloudWatch

  • Configure CloudWatch to capture logs from the running ECS tasks.

Conclusion

In conclusion, our project showcased the seamless integration of various AWS services and tools to achieve a robust and scalable deployment pipeline. From source code management on GitHub to containerization with Docker, and orchestration using ECS and ECR, every step was meticulously crafted to ensure a smooth deployment process. IAM and CloudWatch added the necessary security and monitoring layers, enhancing the overall reliability of our Node.js application on AWS. This journey not only demonstrated the power of these tools individually but also highlighted their synergy in building and managing modern cloud-based applications. As we conclude, we invite you to explore and adapt these practices in your projects, fostering efficient and reliable deployments in the AWS cloud ecosystem.