AWS ECS on Fargate offers a seamless platform for deploying containerized applications with ease and efficiency. In this article, we will guide you through the process of deploying an NGINX application on AWS ECS using Fargate.
What is AWS ECS and Fargate?
AWS ECS (Elastic Container Service) is a highly scalable, high-performance container management service that supports Docker containers and allows you to run applications on a managed cluster of servers. Fargate, on the other hand, is a serverless compute engine for containers that work with ECS, removing the need to manage servers or clusters. Additionally, you can deploy ECS on an EC2 instance, however you would need to manually manage the servers or cluster.
Why are we deploying NGINX? NGINX is a popular open-source web server known for its high performance, stability, and rich feature set. It's often used for load balancing, reverse proxying, and as a web server.
Prerequisites
An AWS account with permission to use ECS
AWS CLI installed
Basic understanding of Docker, NGINX, and AWS AWS ECS
Step 1: Create an ECS Cluster:
A cluster is a logical grouping of your ECS resources, you would need a cluster to deploy a container. in this post, we will be using the default vpc for the cluster
To create a cluster Through AWS CLI aws ecs create-cluster --cluster-name nginx-application
To Create a cluster via AWS Console
Log in to your AWS Management Console, Navigate to the ECS service, and select “Clusters”. Create a new cluster
Step 2: Register task definition:
A Task Definition in AWS ECS is a blueprint for running containers, specifying details like container images, CPU and memory allocation, environment variables, and networking settings.
To Create a task definition via AWS Console
Go to the Task Definitions page on the ECS console.
Create a new task definition and select “Fargate” as the launch type.
Configure the task with the required settings like task size (CPU and memory).
Add a container definition for your NGINX server. Here, you'll specify the image for NGINX (you can use the official NGINX image from Docker Hub).
Step 3: Configure and Launch the Service
A service in AWS ECS creates a task by instantiating a task definition, where a task represents a running container. The service is responsible for managing and maintaining the container's desired state and scalability.
To Create a Service via AWS Console
Return to your ECS cluster and select “Services”.
Create a new service and select the task definition you created.
Configure the service - set the number of desired tasks, and network and security settings.
Launch the service. AWS Fargate will start and manage the containers for you.
Step 4: Access the NGINX Application
Find the public IP of your running task (available in the task details in the ECS console).
Access NGINX by entering the public IP in your web browser. You should see the NGINX welcome page.