Deploying Nginx on AWS ECS with Fargate and ALB

Deploying Nginx on AWS ECS with Fargate and ALB

ยท

4 min read

Introduction

Deploy Nginx on AWS ECS effortlessly with Fargate and ALB using this concise guide. Create an ECS cluster, define a Fargate task for Nginx, and set up an Application Load Balancer for seamless traffic distribution. The step-by-step process ensures simplicity, scalability, and resilience. Access Nginx through the ALB's DNS, witnessing the default welcome page. Optionally, scale the service as needed and effortlessly cleanup resources when done. Ideal for those seeking a straightforward approach to containerized web hosting on AWS, this guide combines the power of ECS Fargate and ALB for an efficient and scalable Nginx deployment.

AWS ECS

AWS ECS (Elastic Container Service) is a managed service that simplifies the deployment, management and scaling of Docker containers in the cloud. This fully managed service takes care of the essential details, allowing you to focus on deploying and running your containerized applications seamlessly.

AWS Fargate

AWS Fargate is a technology that you can use with Amazon ECS to run containers without having to manage servers or clusters of Amazon EC2 instances. With Fargate, you no longer have to provision, configure, or scale clusters of virtual machines to run containers. This removes the need to choose server types, decide when to scale your clusters, or optimize cluster packing.

Application Load Balancer

Elastic Load Balancing automatically distributes your incoming traffic across multiple targets, such as EC2 instances, containers, and IP addresses, in one or more Availability Zones. It monitors the health of its registered targets, and routes traffic only to the healthy targets. Elastic Load Balancing scales your load balancer as your incoming traffic changes over time. It can automatically scale to the vast majority of workloads.

Prerequisites:

AWS Free Tier Account

Step 1: Create an ECS Cluster

Go to the ECS service console follow the below instructions and create cluster.

Follow the below steps to create your cluster.

Step 2: Define a Task Definition for Nginx

In the ECS Console, click on "Task Definitions" in the left navigation pane.

Click "Create New Task Definition."

Select the launch type compatibility as "Fargate." Enter a name for your task definition (e.g., "nginx-task").

Define the container: Name: "nginx" Image: Specify the Nginx Docker image (e.g., "nginx: latest"). Port Mapping: Container Port 80 (Nginx's default port).

Here we created task definition successfully.

Step 3: Create ECS Service for Nginx using Fargate with ALB

In the ECS Console, click on "Clusters" and select your cluster.

Click the "Create" button under the "Services" tab.

Choose the launch type as "Fargate."

Choose your task definition ("nginx-task").

Configure service name (e.g., "nginx-service"), set the desired number of tasks to 1.

Choose the load balancer section:

Load Balancer Type: "Application Load Balancer."

Load Balancer Name: "nginx-web-lb".

Container Name: "nginx" (as specified in your task definition). Container Port: 80 (as specified in your task definition).

Configure your network settings. Click through to the end and create the service

Step 4: Access Nginx through ALB

1. Find the DNS of your ALB:

Once the service is running, go to the AWS Management Console, navigate to EC2, and then "Load Balancers."

Find your ALB, and note its DNS name.

nginx-web-lb-464474721.ap-south-1.elb.amazonaws.com

2. Access Nginx:

Open a web browser and go to the ALB's DNS name (e.g., You should see the default Nginx welcome page.

Conclusion

In conclusion, deploying Nginx on AWS ECS with Fargate and ALB offers a streamlined solution for hosting web applications. With the power of Fargate managing infrastructure and ALB handling load balancing, the setup is efficient, scalable, and user-friendly. Here's to simplified deployments and a robust hosting environment on AWS! ๐Ÿš€๐Ÿ’ป

Happy Learning!

Thank you for being part of this community, and here's to many more shared adventures ahead. If you have any questions or topics you'd like me to cover, feel free to drop a comment. Until next time, happy reading and happy exploring

Thank you,

Akshay Nazirkar

ย