Project 6.1 - Deploying NODEJS application using ECS and ECR Amazon services

ECS Cluster

Login to the Aws console, navigate to ECS and start creating a Cluster

Provide Cluster name, VPC/subnet, set it as AWS farmgate (serverless) and enable the monitoring.

ECR Repository

Navigate to ECR and start creating a repository

Make it public, and give a name, operating system as Linux x68,x68-64.

Create an EC2 instance with IAM User Policies for ECR

Create and connect to the EC2 instance

sudo apt-get update
sudo apt install unzip

# Install AWS CLI 2.13
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo unzip awscliv2.zip
sudo ./aws/install
aws --version

Create an IAM USER with the below policies

Configure the terminal to the AWS console

aws configure

Provide the IAM User details like Access Key ID and Access Key

Now the user is configured to the AWS console through CLI

Open the ECR repository we created and click on view push commands

Paste all these commands in the EC2 terminal, before that docker should be installed.

sudo apt install docker.io -y
sudo usermod -aG docker $USER
sudo reboot

Clone the nodejs application from the Git

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

Check the ECR now, it should contain a newly created docker image pushed into it

Creating Task Definition in ECS

In the ECS service dashboard, click on "Task Definitions" in the left sidebar.

Click on "Create new task definition."

Choose a task role based on your application's needs or create a new one or use the existing one which is previously created

Add port no 8000, check it from the docker file

Leave the rest to defaults and click on create

A new task execution role got created and under the Containers section we can find a container

Our task definition is created, and now we need to deploy it.

Click on Deploy > Run task

Choose the Cluster that you want to use

Under Networking, check the security inbound rules and enable port 80

Skip the next and click on Create

The cluster will now provision our task from the task definition and deploy the Flask application

Open the task that is running inside the cluster and access the public:8000