Deploy ECS services using AWS Fargate and Fargate Spot capacity providers for serverless container compute.
Fargate is the default and recommended compute option for this module. With Fargate, AWS manages the underlying EC2 infrastructure so you only define CPU and memory requirements at the task level. Fargate Spot runs tasks on spare AWS capacity at a significant cost reduction but with the possibility of interruption.
Fargate (on-demand)
Guaranteed capacity. Best for production workloads, latency-sensitive services, and tasks that cannot tolerate interruption.
Fargate Spot
Up to 70% cheaper. Best for batch jobs, non-critical background processing, and fault-tolerant workloads that can restart on interruption.
You cannot mix EC2-based capacity providers with Fargate capacity providers on the same cluster. Choose one compute family per cluster.
Creating a cluster with Fargate capacity providers
1
Define the cluster module
Use the cluster sub-module and specify which Fargate capacity providers to enable. Both FARGATE and FARGATE_SPOT are AWS-managed names — you reference them directly rather than creating them.
The default_capacity_provider_strategy controls how tasks are distributed:
base — the minimum number of tasks to always place on this provider before weight applies. In the example above, the first 20 tasks always go to FARGATE.
weight — a relative proportion used to distribute tasks beyond the base. Equal weights (50/50) split tasks evenly. A 60/40 split would send 60% to one provider and 40% to the other.
Set a base on FARGATE to ensure at least some on-demand tasks are always running, then use FARGATE_SPOT for the remainder to reduce costs.
3
Deploy a service onto the cluster
Point the service module at your cluster and define container definitions. The service defaults to FARGATE launch type and awsvpc networking.
Fargate requires awsvpc network mode, which is the default for this module. Each task gets its own elastic network interface (ENI) with a private IP from your VPC subnets.You must provide subnet_ids for the service. The module creates a security group automatically and lets you define ingress and egress rules:
Place tasks in private subnets and expose them through an Application Load Balancer in public subnets. Never assign public IPs to tasks unless required — set assign_public_ip = true only when tasks have no NAT gateway access.
The Fargate example uses a FluentBit sidecar for log forwarding. Add the fluent-bit container definition alongside your application container and configure awsfirelens as the log driver: