> ## Documentation Index
> Fetch the complete documentation index at: https://help.nops.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Run Non-Production ECS Tasks on Fargate Spot

> Run non-production ECS services on Fargate Spot instead of on-demand Fargate.

Fargate Spot runs ECS tasks on spare AWS capacity at a discount to on-demand Fargate, in exchange for tasks that can be stopped with a two-minute warning. That trade-off usually suits development, test and staging services. nOps finds ECS services on on-demand Fargate that are tagged or named as non-production, and estimates the saving at the Fargate Spot discount you already get in the same region.

| | |
| - | - |
| **Cloud** | AWS |
| **Category** | Compute |
| **Service** | Amazon ECS (Fargate) |
| **Action** | Modify |
| **Effort** | Low |
| **Restart needed** | Yes |
| **Can be rolled back** | Yes |
| **Analysis window** | Last 7 days |
| **Source** | nOps |

## Why it matters

Non-production services often run all day on full-price capacity, even though a restarted task costs nothing but a short wait.

## How nOps finds it

nOps reads the last 20 days of ECS Fargate billing (x86 Linux vCPU and memory) and groups it by ECS service, or by cluster for tasks without a service. A service is flagged when at least 90% of its on-demand cost in the last 7 days is non-production, judged by its environment tag, the environment nOps assigns, or words such as dev, test, qa, staging, sandbox or uat in the service or cluster name. The saving is that on-demand cost, scaled to a month, times your own Fargate Spot discount in the region, measured from at least 24 Spot hours you ran there in the last 20 days. Services are left out when you run no Fargate Spot in the region, when commitments cover most of their usage, when they already run mostly on Spot, or when the saving is under \$10 a month.

## Before you start

The tasks must be stateless or able to restart cleanly. Permission to update the cluster and service (`ecs:PutClusterCapacityProviders`, `ecs:UpdateService`).

## How to implement

1. Confirm the service is not production and that its tasks can be stopped and restarted at any time.
2. Make sure the cluster has the **FARGATE\_SPOT** capacity provider (ECS console: **Clusters → your cluster → Infrastructure**, or `aws ecs put-cluster-capacity-providers --capacity-providers FARGATE FARGATE_SPOT`).
3. Update the service to use a capacity provider strategy with FARGATE\_SPOT (for example `aws ecs update-service --cluster CLUSTER --service SERVICE --capacity-provider-strategy capacityProvider=FARGATE_SPOT,weight=1 --force-new-deployment`). Keep a small FARGATE base if you need one task that is never interrupted.
4. Watch the service for a few days for interrupted tasks and slow restarts.
5. Update the capacity provider strategy in Terraform, CloudFormation or CDK so a later deployment does not switch it back.

## Risks and considerations

* Spot tasks can be stopped with a two-minute warning. Handle SIGTERM and keep tasks stateless.
* Fargate Spot runs x86 Linux tasks only. If you move the service to Graviton instead, take that saving, not both.
* When Spot capacity is short, tasks may wait to be placed.
* To roll back, change the capacity provider strategy back to FARGATE and redeploy.

## FAQs

> [accordion] Why doesn't nOps show this for every non-production service?
>
> nOps prices the saving at the Fargate Spot discount you already get in that region. If you run no Fargate Spot there yet, it has no measured discount to use, so it does not estimate one.

> [accordion] How does nOps decide a service is non-production?
>
> From its environment tag first, then the environment nOps assigns to the account or resource, then words in the service or cluster name such as dev, test or staging.

## Related

* [Migrate Fargate Tasks to Graviton](https://help.nops.io/inform/supported-recommendations/migrate-fargate-tasks-to-graviton)
* [Run EMR Task Nodes on Spot Instances](https://help.nops.io/inform/supported-recommendations/run-emr-task-nodes-on-spot-instances)
* [Schedule Non-Production EC2 Instances](https://help.nops.io/inform/supported-recommendations/schedule-non-production-ec2-instances)
* [Supported recommendations](https://help.nops.io/inform/supported-recommendations.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.