Day-48: Exploring AWS ECS and Setting up Nginx
Today’s journey dives into AWS Elastic Container Service (ECS), a powerful tool for managing and running containerized applications. Let’s break down ECS, understand its comparison with EKS, and finally implement Nginx on ECS.
What is ECS?
ECS (Elastic Container Service) is a fully managed container orchestration service from AWS. It simplifies running and managing Docker containers without worrying about the underlying infrastructure.
Key Features of ECS:
Launch Types:
Fargate: AWS manages the infrastructure.
EC2: You manage the underlying EC2 instances.
Integration: Seamlessly integrates with AWS services like ELB, Auto Scaling, and Amazon VPC.
Scalability: Automatically scales workloads with ease.
Flexibility: Supports Docker Compose and Kubernetes workflows.
ECS vs. EKS
Feature | ECS | EKS |
Architecture | Centralized control plane | Distributed Kubernetes control plane |
Kubernetes Support | Not natively supported | Fully managed Kubernetes service |
Scaling | Manual scaling policies | Auto-scaling Kubernetes clusters |
Flexibility | Simpler, AWS-driven orchestration | Highly customizable Kubernetes setup |
Community | AWS-centric, smaller community | Large open-source Kubernetes community |
Task: Setting up Nginx on ECS
Requirements:
AWS Account.
AWS CLI configured.
Basic knowledge of Docker and containerization.
Step 1: Create a Docker Image for Nginx
- Write a
Dockerfile
:
FROM nginx:latest
COPY index.html /usr/share/nginx/html
- Create a simple
index.html
file:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to ECS</title>
</head>
<body>
<h1>Hello from Nginx on ECS!</h1>
</body>
</html>
- Build and push the Docker image to Amazon ECR (Elastic Container Registry):
# Authenticate Docker to ECR
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
# Build and tag the image
docker build -t nginx-ecs .
# Push the image
docker tag nginx-ecs:latest <account-id>.dkr.ecr.<region>.amazonaws.com/nginx-ecs:latest
docker push <account-id>.dkr.ecr.<region>.amazonaws.com/nginx-ecs:latest
Step 2: Set Up an ECS Cluster
Create an ECS Cluster:
Go to ECS Console → Clusters → Create Cluster.
Choose Networking only (for Fargate).
Configure the Cluster:
Add a name for the cluster.
Configure networking (choose an existing VPC and Subnets).
Step 3: Define a Task Definition
Create a Task Definition:
Navigate to ECS → Task Definitions → Create.
Select Fargate as the launch type.
Add Container Details:
Container name:
nginx-container
.Image:
<account-id>.dkr.ecr.<region>.
amazonaws.com/nginx-ecs:latest
.Port:
80
.
Step 4: Deploy the Service
Create a Service:
Go to your ECS Cluster → Services → Create Service.
Choose Fargate and your task definition.
Service Details:
Number of tasks:
1
.VPC and Subnets: Select those used earlier.
Configure security groups to allow HTTP traffic on port
80
.
Step 5: Test Your Deployment
Retrieve the Public IP or Load Balancer URL from the service.
Open the URL in a browser to see the Nginx welcome page:
Hello from Nginx on ECS!
Key Takeaways:
ECS simplifies containerized application management with minimal infrastructure overhead.
Choosing between ECS and EKS depends on your workload and familiarity with Kubernetes.
Deploying Nginx on ECS showcases how easily applications can be containerized and scaled using AWS tools.
Happy Learning! 🚀
Subscribe to my newsletter
Read articles from Dhruv Moradiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by