In this lesson, you will deploy a simple Node.js application to AWS ECS. Before working with ECS using the AWS Console, review the two public demo projects available on Docker Hub: • https://kodekloud.com/ecs-project1Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
• https://kodekloud.com/ecs-project2 Pull these images to follow along with the lesson.
Project 1 Overview
Project 1 features a basic Node.js application using the Express framework to serve a simple HTML file. A GET request to the root path returns the HTML document.index.html
Express Server Code
The Express server is configured to render the HTML page. The application listens on port 3000.Dockerfile
The Dockerfile below packages the application and exposes port 3000. When configuring your ECS container, ensure that port 3000 is specified.Deploying with the ECS Console
Navigate to the AWS Console and search for Elastic Container Service (ECS). When you first use ECS, you will encounter a quick-start wizard. Although the wizard includes sample apps, choose a custom configuration to understand each underlying component.Step 1 – Using the Quick Start Wizard
When prompted by the wizard:- Click the Get started button.
- Instead of selecting one of the example applications, choose Custom to provide your own configurations.


- Container Name: ECS-Project1
- Image: kodekloud/ECS-Project1 (public repository; no credentials required)
- Memory Limits: Adjust as needed.
- Port Mapping: Specify port 3000 (TCP). As the Express app listens on port 3000, set the container port to 3000.
Unlike a typical Docker run command (e.g.,
-p 80:3000), in ECS the external port must match the container port (e.g., 3000 mapped to 3000).
Service and Cluster Setup
After the container configuration, click Next to proceed to the service definition. ECS will generate a service named ECS-project1-service. You may choose to attach a load balancer (for this demo, select None). The wizard will automatically provision a new cluster and VPC along with the required subnets.

Exploring ECS Components
Task Definitions
Task definitions serve as blueprints for your container configurations (including port mappings, environment variables, and volumes). Under Task Definitions in the ECS Console, locate the task definition for this project, noting that revisions indicate configuration changes.


Clusters and Services
Within Clusters, the wizard-created cluster displays the active service ECS-project1-service. This service is associated with one desired task and, later, one running task.


If multiple tasks are running, each task will have a unique IP address. This dynamic nature is why a load balancer is crucial—it provides a stable endpoint for clients.
Tearing Down the Quick Start Deployment
After confirming a successful deployment, delete the resources created via the quick start wizard. Delete the ECS service by navigating to the cluster, selecting the service, and confirming deletion (type “delete me” when prompted). Then, delete the cluster.
Deploying from Scratch Using Fargate
Creating a New Cluster
- In the ECS Console, click Create Cluster.
- Choose the “Networking only” option (Fargate).
- Provide a cluster name (e.g., “cluster1”). Leave the default VPC CIDR block and subnets intact.
- Click Create.

Creating a Task Definition
- In the ECS Console, navigate to Task Definitions and click Create new Task Definition.
- Select Fargate as the launch type.
- Name the task definition (e.g., “ECS-Project1-taskdef”) and choose the appropriate IAM role (this may have been auto-created if you previously ran the quick start wizard).
- Choose Linux as the operating system and keep the default execution role.
- Specify a minimal task size for this demo.

- Add a container with these settings:
- Container Name: node app
- Image: kodekloud/ECS-Project1
- Health Check Command:
- Port Mapping: 3000

Creating a Service from the Task Definition
- Within your cluster (“cluster1”), go to the Services tab and click Create.
- Set the Launch type to Fargate and the Operating system to Linux.
- Select the latest revision of your task definition (“ECS-Project1-taskdef”).
- Name your service (e.g., “project1-service”) and choose the desired number of tasks (for instance, 2 to demonstrate scaling).
- Click Next.

- For the network configuration:
- Select the VPC created for ECS.
- Choose the two subnets.
- Edit the default security group to permit incoming traffic on port 3000 (instead of port 80).
- Skip the load balancer configuration for this demo.
- Optionally disable autoscaling and click Next.






Updating the Application
Suppose you decide to update the application by modifying the HTML. For example, you can add extra exclamation points to the H1 tag.Updated index.html




Cleanup and Next Steps
After verifying the updated deployment, you can delete the application resources if desired. In the ECS Console, delete the service (confirm by entering “delete me”) and ensure all tasks are terminated.
