Docs/ECS Fargate hibernation

ECS Fargate hibernation

Scale the Fargate services of a dev/test ECS cluster to zero outside working hours and restore them afterwards.

What you can manage

SnoozeDB discovers ECS clusters through the AWS API and hibernates a cluster as a whole: every eligible service in the cluster is scaled to zero tasks, then restored to its saved task count on wake. A cluster with eligible services appears in the dashboard next to your EKS clusters.

A service is eligible when all of these are true:

  • It uses the REPLICA scheduling strategy. DAEMON services are not supported.
  • It uses the ECS deployment controller, with any deployment strategy (rolling, blue/green, linear or canary). Services deployed by CodeDeploy or an external controller are not supported.
  • It runs on Fargate or Fargate Spot only. Services on EC2 capacity providers, or on a mix of EC2 and Fargate, are not supported.
  • It is ACTIVE and has a single deployment that is completed. A service that is mid-deployment is not touched.
  • It does not carry the tag snoozedb:enabled=false.

An ineligible service is listed with its reason and is never modified. The other services of the cluster can still be hibernated. A cluster with no Fargate service is not stored.

Each managed ECS cluster uses one unit of your plan capacity, shared with managed RDS databases and EKS clusters. Hibernation requires an eligible paid workspace or a valid trial.

Enable the module and update the stack

ECS access is an optional IAM module. Without it, SnoozeDB makes no ECS call for the account, including discovery.

  1. Open Settings → Cloud integrations and enable the ECS Fargate hibernation module.
  2. Update the account's CloudFormation stack with the new template.
  3. Return to Resources scheduling and select Sync Now.
  4. Review the cluster rows in To triage. Choose Manage or Protect, as for RDS or EKS.

Until the stack is updated, an operation fails with a message that points to Cloud integrations, and nothing is changed in AWS.

AWS connection and permission updates

Permissions and the RegisterScalableTarget scope

The module grants read access to ECS and Application Auto Scaling (ecs:ListClusters, ecs:DescribeClusters, ecs:ListServices, ecs:DescribeServices, ecs:DescribeTaskDefinition and application-autoscaling:DescribeScalableTargets). It grants two write actions:

  • ecs:UpdateService, limited to service ARNs in your account.
  • application-autoscaling:RegisterScalableTarget, on Resource "*".

Safeguards on the SnoozeDB side:

  • SnoozeDB calls RegisterScalableTarget only with ServiceNamespace ecs and ScalableDimension ecs:service:DesiredCount.
  • The ResourceId is always service/<cluster>/<service>, built from a service in the verified inventory, and checked again against your account and region before the call.
  • A test asserts these three parameters.
  • The module stays off until you enable it, and you can turn it off again and update the stack to remove the permissions.

Control Tower, SCPs and CloudFormation Hooks

AWS Organizations and Control Tower can block the actions SnoozeDB needs, whatever the IAM role allows.

  • One stack per member account: each member account of the organization has its own SnoozeDB CloudFormation stack and role. Enable the module and update the stack in every account where you want ECS hibernation.
  • Service control policies: if an SCP denies ecs:UpdateService or application-autoscaling:RegisterScalableTarget, the operation fails with this message:
    Blocked by a service control policy of your AWS Organization. Ask your landing zone administrator to allow ecs:UpdateService and application-autoscaling:RegisterScalableTarget, then retry.
    Updating the stack does not change this. Ask the landing zone administrator to allow both actions for the SnoozeDB role.
  • Proactive controls: a Control Tower proactive control (a CloudFormation Hook) can reject the stack update because of the Resource "*" statement. The update then fails in CloudFormation, before SnoozeDB is involved. Ask the administrator for an exception or review the control.

SnoozeDB suspends auto scaling before it scales a service down. An SCP that denies Application Auto Scaling therefore stops the hibernation before any service is set to zero.

Hibernate and wake a cluster

Open the cluster, choose Hibernate now and confirm. SnoozeDB allows one active operation per cluster, and its existing scheduler advances the operation on every pass. An operation that does not finish within 30 minutes fails and leaves the cluster in an error state.

What hibernation does

  1. It saves the desired count of each eligible service and, for services with an Application Auto Scaling target, the minimum, maximum and suspended flags.
  2. It suspends scaling on each target and sets its minimum and maximum to zero, so auto scaling cannot start tasks during the sleep.
  3. It sets each service to a desired count of zero.
  4. It waits until no task is running or pending, then marks the cluster asleep.

What wake does

  1. It checks each service against the saved configuration (see recovery below).
  2. It restores each desired count, then restores each scalable target with its saved minimum, maximum and suspended flags. A target that was already suspended before the sleep stays suspended.
  3. It waits until the running tasks reach the restored count, then marks the cluster awake and clears the saved configuration.

Temporary AWS or network errors, such as throttling, are retried on the next pass. A service deleted during the sleep is skipped and does not block the others.

What it does not do

  • Tasks started outside a service, with RunTask or an EventBridge schedule, are not stopped. The dashboard shows how many such tasks are running.
  • It does not stop services that are not eligible.
  • Ephemeral storage is lost when a task stops.
  • SnoozeDB checks that tasks are running again. It does not check whether your application is healthy, so run your own check after the first wake.

Schedule hibernation

Each cluster can have one hibernation schedule, set from the cluster row: Business hours, which uses your organization's hours, or a custom schedule. ECS schedules run in your organization's timezone. Only an owner or admin can change a schedule, with MFA when the organization requires it.

Outside the active window, the scheduler hibernates the cluster. Inside it, the scheduler wakes the cluster. A manual action that contradicts the schedule holds until the schedule's next transition, for at most 7 days. A schedule does not wake a cluster whose last operation failed.

If you downgrade to the Dev plan, managed ECS clusters return to To triage and cannot be hibernated again. The schedule of an awake cluster is disabled. A cluster that is asleep or mid-operation keeps its schedule, so its scheduled wake still runs.

Terraform and CloudFormation during the sleep

Infrastructure as code can reset a service's desired count while the cluster sleeps, for example when a pipeline runs terraform apply or updates a CloudFormation stack. The dashboard warns when a service appears to be managed this way.

  • If the run restored a service to its saved values, the wake skips that service and restores the others.
  • If it set any other value, the wake stops with the error "Service <name> changed while asleep; restore it manually" and restores nothing.

Avoid deployments to a hibernated cluster, or ignore desired_count changes in your Terraform configuration (lifecycle ignore_changes).

Recover after a failed operation

When an operation fails, the cluster shows Action required with the error message, and SnoozeDB keeps the saved configuration. A schedule does not wake a cluster in error. Fix the cause, then choose Wake up.

  • Missing permissions: enable the ECS module and update the CloudFormation stack from Settings → Cloud integrations, then retry.
  • SCP denial: ask your landing zone administrator to allow the two actions, then retry.
  • Timeout: an operation unfinished after 30 minutes fails. Check the services and their tasks in the ECS console, then choose Wake up, or Hibernate now after a failed hibernation that left no saved configuration.
  • Service changed during sleep: before waking, SnoozeDB accepts each service in either its asleep state or its saved state. The desired count and the scalable target are checked separately, so a sleep or wake that stopped half-way can still be resumed. Any other value fails the wake without restoring anything. Set the service back to one of those states (typically the saved desired count and scaling range), then choose Wake up again.

Do not delete the saved configuration to clear an error. Only a completed wake clears it, and the operation history keeps a record.

Remaining costs and savings

While a cluster sleeps, these keep billing: load balancers, NAT gateways, public IPv4 addresses, CloudWatch logs and databases. Savings Plans commitments also remain in force, including Compute Savings Plans that covered the Fargate usage.

SnoozeDB estimates the hourly Fargate cost of a cluster from each service's task count, vCPU, memory, architecture and region, when the hibernation starts. Fargate Spot services are priced at the on-demand rate, so their estimate is high. Each completed or ongoing sleep adds its estimated hourly cost multiplied by its duration to your savings in dollars, on the dashboard, the Impact page and the monthly report.

ECS clusters are not part of the "runtime stopped" percentage, which still covers RDS and EC2 only. A cluster's hours appear in its own row, and its savings are included in the dollar figures.

Validate on a dedicated dev cluster first: check that every task stops, that the saved counts return after wake, and measure the wake time before relying on a morning schedule.