Kashish Trivedi
2 min readAug 4, 2023

Step-by-step example of setting up Nginx on an AWS ECS cluster using the Fargate launch type:

Step 1: Create an ECS Task Definition
- Go to the AWS Management Console and navigate to the ECS service.
- Click on "Task Definitions" in the left-hand menu and then click "Create new Task Definition."
- Select the Fargate launch type and click "Next."
- Give your task definition a name and optional description.
- Click "Add container" to configure your Nginx container:
- Set the container name (e.g., "nginx-container").
- Specify the Nginx Docker image (e.g., "nginx:latest").
- Define the port mappings, such as 80:80 for HTTP traffic.
- Configure any necessary environment variables.
- Click "Add" and then "Create."

Step 2: Create an ECS Cluster
- In the ECS service, click on "Clusters" in the left-hand menu and then click "Create Cluster."
- Choose the "Networking only" cluster template and click "Next."
- Give your cluster a name, and optionally, a description.
- Click "Create."

Step 3: Create an ECS Service
- In the ECS service, click on "Clusters" in the left-hand menu and select the cluster you created in Step 2.
- Click "Create" to create a new service.
- Choose "Fargate" as the launch type and click "Next."
- Configure your service settings:
- Give your service a name (e.g., "nginx-service").
- Set the number of desired tasks to run, such as 2 for redundancy.
- Select the task definition you created in Step 1.
- Set up optional service discovery if needed.
- Click "Next."

Step 4: Configure Load Balancer (Optional)
- If you want to distribute traffic across multiple Nginx containers, set up an Application Load Balancer (ALB).
- In the EC2 service, click on "Load Balancers" in the left-hand menu and then click "Create Load Balancer."
- Choose "Application Load Balancer" and click "Next."
- Configure your ALB settings, such as listener ports and security groups.
- In the "Configure Routing" step, create a new target group and select "IP" as the target type.
- Click "Next" and "Create."

Step 5: Attach the ECS Service to the Load Balancer (Optional)
- Go back to your ECS service and edit it.
- In the "Load Balancing" section, select the ALB you created in Step 4.
- Choose the target group you created in Step 4.
- Click "Add to load balancer" and then click "Update."

Step 6: Review and Launch
- Review all your settings and configurations to ensure they are correct.
- Click "Create Service" to launch the ECS service and start running Nginx containers on the Fargate cluster.

That's it! You have successfully set up Nginx on an ECS cluster using the Fargate launch type.

If you set up a load balancer, you can now access your Nginx service through the ALB’s DNS name.

If you didn’t set up a load balancer, you can access the individual container IPs, but keep in mind that these IPs might change due to scaling or container restarts.