Table of Contents
Introduction
Setup express js project
Deploy into ECS
Free Up
1) Introduction
To understand how ECS vs. EKS vs. Fargate differ, consider how AWS’s container services are organized.
AWS Registry services enable you to store and manage container images. Amazon Elastic Container Registry (ECR) is in this category.
AWS Orchestration services let you manage where and when your containers run. The two services in this category are Amazon ECS and Amazon EKS.
AWS Compute services power your containers. AWS provides two such services: AWS Fargate and Amazon Elastic Compute Cloud (EC2).
What Is Amazon ECS?
It is a Amazon’s Docker-based container scheduling and orchestration system that the AWS team built from scratch.
Amazon ECS is a fully managed container service designed to streamline your focus on code improvement and service delivery, relieving the burden of building, scaling, and maintaining Kubernetes cluster management infrastructure.
Often hailed as Amazon's Docker-as-a-Service platform, Amazon ECS also offers an on-premises version known as Amazon ECS Anywhere.
Containers in Amazon ECS are defined within a task definition, facilitating the execution of individual tasks or groups of tasks within services. These services are configurations that allow simultaneous execution of a specified number of tasks within a cluster.
What Is Amazon EKS?
Amazon Elastic Kubernetes Service (EKS) is Amazon’s fully managed Kubernetes-as-a-Service platform that enables you to deploy, run, and manage Kubernetes applications, containers, and workloads in the AWS public cloud or on-premise.
"Utilizing Amazon EKS eliminates the need for manual installation, configuration, and maintenance of Kubernetes. Instead, simply set up and connect worker nodes to Amazon EKS endpoints. AWS takes care of all administrative tasks related to the Kubernetes control plane, such as patching, upgrades, replacing unhealthy instances, security configurations, and scaling containerized workloads across multiple AWS Availability Zones.
Moreover, Amazon EKS seamlessly scales backend persistent layers and API servers. It's worth noting that Amazon EKS is Certified Kubernetes-Compatible, ensuring seamless compatibility with applications designed for upstream Kubernetes."
What is AWS Fargate?
AWS Fargate stands out as a fully managed serverless compute service, streamlining container management by automating a majority of tasks. While relinquishing some control, users can still define resource parameters and access controls. However, Fargate abstracts away decisions regarding specific AWS instance types and scaling strategies, handling these aspects through automated algorithms.
Primarily categorized as a Container-as-a-Service (CaaS) solution, Fargate seamlessly integrates as an operational mode within ECS for Docker-based containers and EKS for Kubernetes-based containers.
Notably, AWS Fargate ensures security by running each EKS pod or ECS task within its own isolated and dedicated runtime environment.
For a quick comparison, deploying ECS on Fargate offers a more streamlined approach compared to traditional EC2 instances, where Fargate handles resource provisioning and scaling automatically.
2) Setup express js project
install the node js in the machine
sudo apt update
sudo su -
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt install -y nodejs
install the docker
sudo apt install docker.io
sudo chmod 666 /var/run/docker.sock
create the index.js
// Import the express module
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello, World! Welcome........'); // Send a response to the client
});
app.get('/health', (req, res) => {
res.send('Working fine........'); // Send a response to the client
});
const port = 4000;
// Start the server and listen on the specified port
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
create the docker file
FROM node:21
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Expose the port the app runs on
EXPOSE 4000
# Command to run the application
CMD ["node", "index.js"]
{
"name": "nodeapp",
"version": "1.0.0",
"description": "this is node js application",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "sahadev dahit",
"license": "ISC",
"dependencies": {
"express": "^4.19.2"
}
}
Configure the aws cli
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
3) Deploy into ECS
Create the access key
then configure into the machine
3) Deploy into ECS
Attach the policy
if still not working then you can attach Administration Access policy
Create the repository
copy and paste these command s into the instance/machine
what is does here is it will login with credentials and create the docker image and push that docker image into the repository
Create the tasks
create the tasks
create the cluster
create the service
Here we create the cluster sucessfully
Let's check the tasks
also check the load balancer
if you want changes into the new version then you need to check the force deployment
4) Free Up
In this way we can deploy the web app in the aws ecs properly.
Thanks for reading ....................................