# Day-48 - Set Up Nginx on AWS ECS (Elastic Container Service)

Today, we'll dive into setting up Nginx on AWS ECS (Elastic Container Service).By leveraging ECS, we can easily deploy and manage containerized applications. Let's get started!

Step 1: Create an ECS Cluster

To begin, let's create an ECS cluster to host our Nginx container. Here's how you can do it:

1. Log in to the AWS Management Console.
    
2. Navigate to the ECS service.  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686881023464/43894d5e-a29f-4c3f-965e-39cb9b702f3a.png align="center")
    
3. Click on "Clusters" and then "Create Cluster".
    
4. Select the desired cluster type and configuration (we will use fargate here)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686881309225/b9b4c5cc-5044-49e2-9a3d-9211919c74c5.png align="center")
    
5. Configure the cluster settings, including the cluster name, instance type, and desired capacity.  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686881574133/4c62a3a2-fb88-4c56-bb5c-0c8c82f5b2f7.png align="center")
    
6. Review the settings and create the ECS cluster.  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686881724787/4feab571-dbef-4b99-9e47-44a88b1a860e.png align="center")
    

Step 2: Create a Task Definition

1. Go to the ECS service in the AWS Management Console.
    
2. Click on "Task Definitions"(Side panel) and then "Create new Task Definition".  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686881799587/498e50d9-6388-4c68-93b6-389f10877b70.png align="center")
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686881833664/e83affdd-2ce2-4288-8adb-62bcf9df04d4.png align="center")

1. Choose the launch type compatibility (Fargate) based on your cluster configuration.
    
2. Define the container properties, such as the container name, image, port mappings, and any additional configurations specific to Nginx.  
      
    For image uri , we will use [public.ecr.aws/nginx/nginx:1-alpine-perl](http://public.ecr.aws/nginx/nginx:1-alpine-perl) ([https://gallery.ecr.aws/nginx/nginx](https://gallery.ecr.aws/nginx/nginx))
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686882333452/7bde3b79-09d9-4eb0-b7d7-7a995343a923.png align="center")
    
    We will monitor using cloud watch
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686882743017/ff8be4ff-f893-47aa-a597-d72b38b6abec.png align="center")
    
3. Review the settings and create the task definition.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686882800317/76528d3e-7625-40f8-8ab4-d5a2562de1b9.png align="center")
    

Step 3: Configure an ECS Service

1. In the ECS service, click on "Clusters" and select the cluster you created in Step 1.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686882890086/4d76cd93-2d2b-4b29-9a55-a904272b3263.png align="center")
    
2. Click on the "Services" tab and then "Create".  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686882919923/18f3accf-d807-4e92-b044-05c21227f644.png align="center")
    
3. Configure the service settings, including the service name, launch type, and desired number of tasks.
    
4. Select the task definition created in Step 2.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686883077655/739b43bb-94f5-4354-9e98-6116af112920.png align="center")
    
5. Configure the network and security group settings for the service.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686883153102/a74cca6f-21f8-48ce-95ad-e2a8e9d4b5a3.png align="center")
    
6. Review the settings and create the ECS service.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686883380735/21c12211-4bad-443f-abf5-4bcab3674b73.png align="center")
    

Step 4: Access Nginx on ECS

1. Go to the ECS service and select the cluster and service you created.
    
2. In the service details, click on the "Tasks" tab.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686883474098/709ded54-afc3-4e7a-8ae9-e559d7444b98.png align="center")
    
3. Locate the running task and click on the task ID.
    
4. In the task details, find the public IP or DNS of the container.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686883544496/a7241b4c-a133-4ba4-bab7-83eb13e59965.png align="center")
    
5. Open a web browser and enter the Nginx container's IP or DNS to access the Nginx welcome page.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686883730026/22bbb6cc-22fe-47fb-8d85-6771ac698fd5.png align="center")
    

Congratulations! You have successfully set up Nginx on AWS ECS. By leveraging the power of ECS, you can easily deploy and manage containerized applications, providing scalability and flexibility to your infrastructure.  

If you have any questions or suggestions, please feel free to leave a comment below. See you another day with another challenge.
