This guide walks you through deploying a working ECS cluster with a Fargate service using the integrated root module. The cluster will run a sample frontend container with Fargate on-demand and Fargate Spot capacity providers.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/terraform-aws-modules/terraform-aws-ecs/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Terraform >= 1.5.7 installed (install guide)
- AWS credentials configured in your environment (
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY, or an IAM role via instance profile / SSO) - Existing VPC and subnets — you need subnet IDs to place your ECS tasks
Steps
Configure the AWS provider
Create a
versions.tf file to pin the provider versions required by the module:Deploy an ECS cluster with a Fargate service
Create a
main.tf with the integrated root module. This configuration creates a cluster with Fargate on-demand and Fargate Spot capacity providers, and deploys a service with two containers: a FluentBit sidecar for log forwarding and the application container.Replace
subnet_ids, target_group_arn, and referenced_security_group_id with real values from your AWS account before applying.What was created
After a successful apply, you have:| Resource | Description |
|---|---|
| ECS cluster | Named ecs-integrated with Fargate and Fargate Spot capacity providers |
| Capacity provider strategy | 50/50 weight split between FARGATE (with a base of 20) and FARGATE_SPOT |
| ECS service | ecsdemo-frontend service with a task definition and two container definitions |
| Task definition | Registers the fluent-bit and ecs-sample container definitions with their CPU/memory allocations |
| CloudWatch log group | Created by the module for ECS cluster execute command logging |
| Security group | Created for the service with the ingress/egress rules you specified |
| Service IAM role | Created automatically because the service uses a load balancer target group |
| Task execution IAM role | Grants ECS permission to pull images and write logs on behalf of your tasks |
Next steps
Fargate guide
Learn how to configure Fargate on-demand and Fargate Spot with mixed capacity provider strategies.
EC2 Auto Scaling
Attach an EC2 Auto Scaling Group as a capacity provider for full compute control.
Logging
Configure CloudWatch logging, FireLens, and FluentBit sidecars for your containers.
Autoscaling
Set up target tracking and scheduled scaling policies for your ECS services.

