AWS PROJECT
Automated deployment of Node.js application on serverless AWS ECS Fargate
with the image repository on ECR and the cloudwatch logging integrated with
proper IAM roles and configuration.
Prerequisites:
• AWS Account: Ensure you have an AWS account with the necessary permissions to
create ECS clusters, ECR repositories, and set up Cloud Watch Logs.
• Install the AWS CLI on created EC2 Instance.
NOTE: After creating instance connect and do update it.
Containerize Your Node.js App:
• Dockerize your Node.js application by creating a Dockerfile in the root of your
project.
Build and Push Docker Image to ECR:
• # Login to AWS ECR
$(aws ecr get-login --no-include-email --region your-region)
• # Create ECR repository
aws ecr create-repository --repository-name your-repo-name --region
your-region
• # Build Docker image
docker build -t your-repo-name .
• # Tag Docker image
docker tag your-repo-name:latest your-ecr-repo-url/your-repo-
name:latest
• # Push Docker image to ECR
docker push your-ecr-repo-url/your-repo-name:latest
NOTE: Please install docker in created instance and add the current user to
docker list.
Create ECS Cluster:
• # Create ECS cluster
aws ecs create-cluster --cluster-name your-cluster-name --region your-
region
Create ECS Task Definition:
• Create a file named ecs-task-definition.json with your configuration.
Replace placeholders with your values OR we can choose another option
in AWS to configure in GUI.
Example for json format.
• # Register ECS Task Definition
aws ecs register-task-definition --cli-input-json file://ecs-task-
definition.json --region your-region
Create ECS Service:
• # Create ECS Service
aws ecs create-service --cluster your-cluster-name --service-name your-
service-name --task-definition your-task-family --desired-count 1 --
region your-region
Set Up CloudWatch Logs:
• Go to the AWS Management Console.
• Navigate to CloudWatch.
• Create a new log group and set up log streams in ECS service
Update ECS Service to Enable CloudWatch Logs:
• Update your ECS service to enable CloudWatch logs by adding the
logConfiguration section to your task definition.
Verify Deployment:
• Check the ECS console to ensure your service is running. Access your
Node.js app using the public IP and port defined in your task definition.