CloudForge
Published 8 min read

How to Schedule AWS Non-Production Resources Off-Hours with Native Tools

Stop development, test and staging resources outside working hours using EventBridge Scheduler, Auto Scaling schedules and tags, with Terraform examples and the pitfalls to avoid.

CloudForge field noteAWS
AWSFinOpsAutomation

Development, test and staging environments are built to be used during the working day. Most of them run all night and all weekend anyway. A week has 168 hours. An environment that is only needed for 50 of them is idle about 70 percent of the time, and on-demand compute bills for every one of those idle hours.

Turning non-production resources off outside working hours is one of the few cost changes that needs no architectural work and carries little production risk. Commercial cost platforms sell this as a scheduling feature. AWS also provides everything required to do it natively. This guide shows how, what the saving really is, and where schedules go wrong.

What you save, and what keeps billing

The compute saving follows directly from the hours. These figures are arithmetic, not a forecast for your account.

Running scheduleHours per weekReduction in compute hours
Always on1680%
Weekdays, 12 hours a day6064%
Weekdays, 10 hours a day5070%
Weekdays, 8 hours a day4076%

That reduction applies to instance hours only. Several charges continue while a resource is stopped:

  • EBS volumes and snapshots attached to stopped instances.
  • RDS storage and backups for stopped databases.
  • Elastic IP addresses, load balancers and NAT gateways, which bill by the hour regardless of the instances behind them.
  • EKS control planes, which bill per cluster hour even with zero nodes.

So a 70 percent cut in compute hours might be a 45 to 60 percent cut in the environment's total cost, depending on how much of it is storage and networking. Check a real bill before quoting a number.

Check commitments first

There is one case where scheduling saves nothing in the short term. If Savings Plans or Reserved Instances already cover the non-production instances, the commitment is paid whether the instances run or not. Stopping them only helps if the freed commitment can apply to other usage, which Compute Savings Plans often can and instance-specific reservations often cannot.

Before building schedules, look at Savings Plans utilization and coverage in Cost Explorer. If utilization would fall when non-production stops, scheduling is still right, but the saving arrives when you resize the next commitment. The Savings Plans and Reserved Instances guide explains how the two differ.

Choose a scheduling method

MethodBest forTrade-off
EventBridge Scheduler calling service APIs directlyA known, small set of instances or databasesResource IDs are listed in the schedule
EventBridge Scheduler invoking a Lambda function or Systems Manager AutomationTag-based scheduling in one accountYou maintain a small function or runbook
Instance Scheduler on AWSMany accounts and Regions, EC2, Auto Scaling groups and RDSA deployed solution with its own running cost
Auto Scaling scheduled actionsAnything already in an Auto Scaling groupOnly applies to those groups
Scaling node groups to zeroEKS and other container platformsWorkloads must tolerate rescheduling

Start with the simplest one that covers your case. Many teams never need more than the first and fourth.

Method 1: EventBridge Scheduler with a universal target

EventBridge Scheduler can call AWS API operations directly on a schedule, with no Lambda function. AWS calls this a universal target. The example below stops two instances at 19:00 on weekdays and starts them at 07:00, in a named time zone so daylight saving changes are handled for you.

data "aws_iam_policy_document" "scheduler_assume" {
  statement {
    actions = ["sts:AssumeRole"]
    principals {
      type        = "Service"
      identifiers = ["scheduler.amazonaws.com"]
    }
  }
}

resource "aws_iam_role" "office_hours" {
  name               = "nonprod-office-hours-scheduler"
  assume_role_policy = data.aws_iam_policy_document.scheduler_assume.json
}

resource "aws_iam_role_policy" "office_hours" {
  role = aws_iam_role.office_hours.id
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect   = "Allow"
      Action   = ["ec2:StartInstances", "ec2:StopInstances"]
      Resource = "*"
      Condition = {
        StringEquals = { "aws:ResourceTag/Schedule" = "office-hours" }
      }
    }]
  })
}

locals {
  dev_instance_ids = ["i-0123456789abcdef0", "i-0fedcba9876543210"]
}

resource "aws_scheduler_schedule" "stop_dev" {
  name                         = "nonprod-stop-weekday-evening"
  schedule_expression          = "cron(0 19 ? * MON-FRI *)"
  schedule_expression_timezone = "America/Chicago"

  flexible_time_window {
    mode = "OFF"
  }

  target {
    arn      = "arn:aws:scheduler:::aws-sdk:ec2:stopInstances"
    role_arn = aws_iam_role.office_hours.arn
    input    = jsonencode({ InstanceIds = local.dev_instance_ids })
  }
}

resource "aws_scheduler_schedule" "start_dev" {
  name                         = "nonprod-start-weekday-morning"
  schedule_expression          = "cron(0 7 ? * MON-FRI *)"
  schedule_expression_timezone = "America/Chicago"

  flexible_time_window {
    mode = "OFF"
  }

  target {
    arn      = "arn:aws:scheduler:::aws-sdk:ec2:startInstances"
    role_arn = aws_iam_role.office_hours.arn
    input    = jsonencode({ InstanceIds = local.dev_instance_ids })
  }
}

Two details are worth copying. The IAM policy only allows start and stop on instances tagged Schedule = office-hours, so a mistake in the ID list cannot stop a production instance. And the Friday evening stop with a Monday morning start gives you the whole weekend without a separate rule.

The same pattern works for RDS by targeting arn:aws:scheduler:::aws-sdk:rds:stopDBInstance and startDBInstance with the database identifier as input. Test the input format against one database before relying on it.

Method 2: Schedule by tag

Hard-coded IDs go stale. A tag-based approach lets teams opt resources in by adding a tag, with no change to the schedule. The schedule invokes a small Lambda function or a Systems Manager Automation runbook, which finds the tagged resources and acts on them.

The lookup the function performs is the same as this CLI command, which is also a useful way to preview what a schedule would stop:

aws ec2 describe-instances \
  --filters "Name=tag:Schedule,Values=office-hours" \
            "Name=instance-state-name,Values=running" \
  --query "Reservations[].Instances[].[InstanceId,Tags[?Key=='Name']|[0].Value]" \
  --output table

If you need this across many accounts and Regions, do not build it yourself. Instance Scheduler on AWS is an AWS-published solution that starts and stops EC2 instances, Auto Scaling groups and RDS instances from schedules you define, selected by tag, across accounts. It deploys from a CloudFormation template and has a small running cost of its own.

Method 3: Auto Scaling scheduled actions

Instances in an Auto Scaling group should not be stopped individually, because the group will replace them. Set the group's size on a schedule instead.

resource "aws_autoscaling_schedule" "scale_in_evening" {
  scheduled_action_name  = "nonprod-evening-zero"
  autoscaling_group_name = aws_autoscaling_group.staging_web.name
  recurrence             = "0 19 * * MON-FRI"
  time_zone              = "America/Chicago"
  min_size               = 0
  max_size               = 0
  desired_capacity       = 0
}

resource "aws_autoscaling_schedule" "scale_out_morning" {
  scheduled_action_name  = "nonprod-morning-up"
  autoscaling_group_name = aws_autoscaling_group.staging_web.name
  recurrence             = "0 7 * * MON-FRI"
  time_zone              = "America/Chicago"
  min_size               = 2
  max_size               = 6
  desired_capacity       = 2
}

Method 4: Containers and Kubernetes

For EKS, the cost is in the nodes. Scale non-production managed node groups to zero in the evening and restore them in the morning:

aws eks update-nodegroup-config \
  --cluster-name staging \
  --nodegroup-name general \
  --scaling-config minSize=0,maxSize=6,desiredSize=0

If the cluster uses Karpenter or another node autoscaler, scale the workloads to zero replicas instead and let the autoscaler remove the empty nodes. The control plane fee continues either way. For environments used only occasionally, creating the cluster from code when needed can cost less than keeping it. For ECS services, set the desired count to zero on the same schedule.

Databases need extra care

  • A stopped RDS instance does not stay stopped. AWS starts it again automatically after seven days. A daily schedule handles this naturally. A one-time manual stop does not.
  • Not every configuration can be stopped. Check the RDS documentation for your engine and deployment type before planning around it.
  • Storage keeps billing. For a large database with small compute, the saving is modest.
  • Start databases first. Applications that start before their database is available may fail health checks and need a restart. Schedule the database 15 to 30 minutes ahead of the application tier.
  • Consider serverless options for development databases that sit idle most of the day. Capacity that scales down with no activity can remove the need for a schedule.

What goes wrong, and how to prevent it

ProblemPrevention
Someone is working late and the environment disappearsPublish the schedule, and provide a self-service way to extend it, such as a temporary tag the function respects
A production resource is stoppedEnforce the tag condition in IAM, and never grant the scheduler role unscoped stop permissions
Data on instance store volumes is lostInstance store data does not survive a stop. Use EBS for anything that must persist
Public IP addresses change after restartUse Elastic IPs or DNS names, not auto-assigned public addresses
Morning start fails for lack of capacityStart early enough to notice, alert on failed schedule invocations, and allow more than one instance type where possible
Scheduled jobs that ran overnight stop runningInventory cron jobs, backups and batch work before enabling the schedule
The schedule quietly stops workingSend failed invocations to a dead-letter queue and alarm on it

Roll it out in stages

  1. Inventory. List non-production accounts and resources with their owners. Missing owners are the first finding.
  2. Tag. Agree on one tag key and a small set of values, such as office-hours, always-on and on-demand.
  3. Pilot with one team. Run for two weeks and collect what broke.
  4. Default to scheduled. For new non-production resources, make office-hours the default and require a reason for always-on.
  5. Report. Show hours saved and cost avoided per team each month, so the schedule is seen as a result and not only as an inconvenience.
  6. Resize commitments. At the next Savings Plans review, size against the new, lower baseline.

Scheduling is usually the first change in a wider cleanup. For what comes next, see how to reduce AWS costs and cutting cloud costs without reliability risk. If non-production sprawl is a symptom of unclear ownership across accounts, that is where CloudForge's AWS cost optimization work starts.

Sources

Related expertise

Put this into practice

AWS Well-Architected Review AWS cost optimization Cloud migration consulting
Continue learning
AWS Private Pricing Agreements (EDP): How to Size the Commitment and Negotiate Terms8 min read How to Reduce AWS NAT Gateway Costs: Find the Traffic, Then Fix the Route9 min read Kubernetes Cost Optimization Providers: Tools, Platforms and Consultants Compared7 min read

Want this applied to your own cloud bill?

CloudForge traces spend to owners, removes waste, plans commitments and sets up the review cadence that keeps savings in place.

See FinOps consulting