If you're looking to run a web server on AWS's Elastic Container Service (ECS) using Fargate launch types, Nginx is a solid choice. AWS offers official images for Nginx that can be quickly deployed, making setup a breeze. Let's walk through the process.
Create an ECS Cluster
Login to AWS Console and search for ECS in the services, You will see something as below. Now Click on Clusters and Create Cluster
Give the name and it gets Default namespace as name. Infrastructure as AWS Fargate (serverless)
We do not need the monitoring to be enabled for now as it will add cost. You can add tags, that define resource usage and purpose.
Cluster creation is in progress, you can also view it in CloudFormation
You can see the ECS Cluster task was created successfully in CloudFormation stack!
Create task definition
In the ECS dashboard on the left side click on Task Definition and Create new task definition
Give a name to Task definition
Setting Infrastructure requirements, Keeping Launch type AWS Fargate , OS - Linux, Task size - 1 CPU and 3GB Memory
Set the Container Values. Set Name, Choose the image https://gallery.ecr.aws/nginx/nginx Keeping other things as default and Create
Task Definition has been created.
Create Service
Now, go back to the created cluster and click on services to Create Service
Service has picked existing Cluster and compute configurations that were defined before
For the Deployment configuration, Keeping Application type- Service, Choosing Task Definition Family and providing Service name
Keep other things default and click on Create
Your Service is available to serve!
Accessing your NGINX service
Go to Cluster -> services -> Tasks
Select Task -> Configuration -> get Public IP of the container
Browse public Ip and Your Nginx is Running!
Your Nginx container running on AWS ECS with the Fargate launch type.
This is how you can deploy any container with the help of ECS service. This service is not Free so don't forget to delete the created resources. To delete the Task definition first Deregister the same then only it will allow you to delete.
This is not that EASY! Remember hands-on practice is the only key to better understanding!
Happy Learning!