Fargate Spot Containers (70 % cheaper)
AWS architecture template · ECS with FARGATE_SPOT capacity provider — up to 70 % savings over on-demand Fargate. SQS-driven task scaling with graceful SIGTERM handling for Spot interruptions.
Fargate Spot Containers (70 % cheaper) is a free AWS architecture template built with CloudWatch, ECS, Fargate, IAM, Load Balancer and SQS. Open it in TheArchitect to edit the diagram, estimate monthly cost, and export the CloudFormation or Terraform that deploys it.
AWS services in this template
- CloudWatch
- ECS
- Fargate
- IAM
- Load Balancer
- SQS
Deployment notes
Needs input
- Configure FARGATE_SPOT capacity provider with a base=0, weight=1 strategy. Add FARGATE provider as fallback with weight=0 (Spot-only by default).
- Handle SIGTERM: on Spot reclaim (30-second warning), drain in-flight work and dequeue back to SQS.
- Cost: Fargate on-demand ~$0.04048/vCPU/hr. Fargate Spot ~$0.012/vCPU/hr (~70 % less).
- Not suitable for stateful or latency-sensitive work. Best for batch, async processing, worker queues.
Generated CloudFormation — 6 resources
| Logical ID | Resource type |
|---|---|
| JobQueuesqs | AWS::SQS::Queue |
| ECSClusterSpotecs | AWS::ECS::Cluster |
| FargateTask05vCPUfargate | AWS::ECS::TaskDefinition |
| InternalALBoptionalelb | AWS::ElasticLoadBalancingV2::LoadBalancer |
| TaskExecutionRoleiam | AWS::IAM::Role |
| QueueDepthAlarmcloudwatch | AWS::CloudWatch::Alarm |
View the full CloudFormation template
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Generated by TheArchitect — https://www.thecloudarchitect.dev",
"Metadata": {
"TheArchitect": {
"Edges": [
{
"From": "QueueDepthAlarmcloudwatch",
"To": "ECSClusterSpotecs",
"Label": "scale trigger"
},
{
"From": "FargateTask05vCPUfargate",
"To": "JobQueuesqs",
"Label": "consume jobs"
},
{
"From": "TaskExecutionRoleiam",
"To": "FargateTask05vCPUfargate",
"Label": "execution role"
}
]
}
},
"Resources": {
"JobQueuesqs": {
"Type": "AWS::SQS::Queue",
"Properties": {
"QueueName": "cost-fargate-jobs",
"VisibilityTimeout": 120,
"MessageRetentionPeriod": 86400,
"ReceiveMessageWaitTimeSeconds": 20
}
},
"ECSClusterSpotecs": {
"Type": "AWS::ECS::Cluster",
"Properties": {
"ClusterName": "cost-fargate-spot-cluster",
"ClusterSettings": [
{
"Name": "containerInsights",
"Value": "enabled"
}
]
}
},
"FargateTask05vCPUfargate": {
"Type": "AWS::ECS::TaskDefinition",
"DependsOn": [
"TaskExecutionRoleiam"
],
"Properties": {
"Family": "cost-fargate-worker",
"Cpu": "512",
"Memory": "1024",
"NetworkMode": "awsvpc",
"RequiresCompatibilities": [
"FARGATE"
],
"ExecutionRoleArn": {
"Fn::GetAtt": [
"TaskExecutionRoleiam",
"Arn"
]
},
"TaskRoleArn": {
"Fn::GetAtt": [
"TaskExecutionRoleiam",
"Arn"
]
}
}
},
"InternalALBoptionalelb": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"Type": "application",
"Scheme": "internal"
}
},
"TaskExecutionRoleiam": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": "cost-fargate-task-exec-role",
"Description": "ECS task execution role — ECR pull + CloudWatch Logs + SQS consume",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
]
}
},
"QueueDepthAlarmcloudwatch": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmName": "cost-fargate-queue-depth",
"AlarmDescription": "Scale ECS service when SQS queue depth > 5 unprocessed messages",
"Namespace": "AWS/SQS",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Statistic": "Average",
"Period": 60,
"EvaluationPeriods": 2,
"Threshold": 5,
"ComparisonOperator": "GreaterThanThreshold",
"TreatMissingData": "notBreaching"
}
}
}
}Generated by TheArchitect from the diagram above. Review values such as names, CIDR ranges and instance sizes before deploying to your account.
Related templates
- Twitter/X Scale TestCloudFront behavior split, API Gateway VPC Link, public/internal ALBs, private app/data subnets, queues, media, and data stores
- Media Transcode PipelineS3 upload triggers a Lambda dispatcher that enqueues SQS jobs consumed by auto-scaled Fargate workers. Renditions are served via CloudFront.
- Aurora GlobalSAA-C03: Route 53 → ALB → Fargate → Aurora global cluster + CloudWatch