Skip to content
Go back

Using AWS ECS for Containerized Applications

Using AWS ECS for Containerized Applications

Introduction

AWS ECS with Fargate enables serverless container hosting. This guide covers creating ECS clusters, task definitions, and deploying services.

Prerequisites

Step 1: Create ECS Cluster

aws ecs create-cluster --cluster-name my-ecs-cluster

Step 2: Register Task Definition

Create task-def.json:

{
  "family": "my-app-task",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "256",
  "memory": "512",
  "containerDefinitions": [
    {
      "name": "my-app-container",
      "image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:latest",
      "portMappings": [{ "containerPort": 80, "protocol": "tcp" }],
      "essential": true,
      "environment": [{ "name": "NODE_ENV", "value": "production" }]
    }
  ]
}

Register:

aws ecs register-task-definition --cli-input-json file://task-def.json

Step 3: Create Service

aws ecs create-service \
  --cluster my-ecs-cluster \
  --service-name my-app-service \
  --task-definition my-app-task \
  --desired-count 2 \
  --launch-type FARGATE \
  --network-configuration "awsvpcConfiguration={subnets=[subnet-012],securityGroups=[sg-012],assignPublicIp=ENABLED}"

Step 4: Configure Load Balancer (Optional)

Attach an ALB in service creation with --load-balancers option.

Step 5: Update Service

aws ecs update-service --cluster my-ecs-cluster --service my-app-service --desired-count 3

Summary

AWS ECS Fargate simplifies container deployments without managing servers. Configure clusters, task definitions, and services with IaC or CLI for scalable, serverless containers.


Share this post on:

Previous Post
Setting Up AWS SES for Transactional Emails
Next Post
Implementing CloudFront Caching for Next.js Apps