ECS Fargate Service

intermediate

Containerised service on ECS Fargate behind an Application Load Balancer. Includes ECR repository, ARM64 tasks, CPU + request-count auto-scaling, health checks, and CloudWatch alarms.

Quick Start

Via CLI (recommended)

npx cdk-starter create

Then select "ECS Fargate Service" from the prompt

Or scaffold directly

npx cdk-starter create --starter ecs-fargate-service

README

ECS Fargate Service

Containerised service on ECS Fargate behind an Application Load Balancer. Includes an ECR repository, ARM64 Fargate tasks, CPU + request-count auto-scaling, and CloudWatch alarms.

Build and push your image

# Get the ECR repo URI from the EcrRepoUri stack output
ECR_URI=$(aws cloudformation describe-stacks --stack-name EcsFargateServiceStack \
  --query 'Stacks[0].Outputs[?OutputKey==`EcrRepoUri`].OutputValue' --output text)

aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_URI
docker buildx build --platform linux/arm64 -t $ECR_URI:latest --push .

Then force a new ECS deployment:

aws ecs update-service --cluster <cluster> --service <service> --force-new-deployment

Prerequisites

  • Node.js ≥ 20
  • AWS CLI configured (aws configure)
  • CDK bootstrapped (npx cdk bootstrap)

Deploy

npm install
npx cdk diff
npx cdk deploy

Tear down

npx cdk destroy