AWS Builder Center
Stop Paying for Idle Dev Servers: Auto-Stop and Start EC2 with EventBridge Scheduler (No Lambda)

Stop Paying for Idle Dev Servers: Auto-Stop and Start EC2 with EventBridge Scheduler (No Lambda)

Cut your dev and test EC2 costs by roughly two-thirds with two schedules and one IAM role. EventBridge Scheduler calls the EC2 API directly, so there is no Lambda function to write or maintain.

Dev and test servers usually run 24/7 even though people use them for about 9 hours a day, 5 days a week. Most "auto-stop" tutorials add a Lambda function, a deployment package, and a log group to babysit. You don't need any of that.
Amazon EventBridge Scheduler has universal targets, which means it can call most AWS APIs directly. In this post, we'll stop an EC2 instance every weekday evening and start it again every morning, using only a schedule and an IAM role.

The math

If an instance only needs to run from 9:00 to 20:00 on weekdays, that is 11 hours x 5 days = 55 hours out of 168 hours in a week. That is about 33% of the week, so you can cut roughly two-thirds of the compute cost for that instance.
A stopped instance does not incur EC2 compute charges, but you still pay for attached EBS volumes and any Elastic IPs. See the section on gotchas below.

Architecture

EventBridge Scheduler --(assumes IAM role)--> EC2 StopInstances / StartInstances
No Lambda and no servers of your own. Scheduler uses the role to call the EC2 API on your behalf.

Step 1: Create the IAM role

The role needs two things: a trust policy so Scheduler can assume it, and a permissions policy to start and stop your instance.
Trust policy ( trust.json ):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "scheduler.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}
Permissions policy ( permissions.json ), scoped to a single instance:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["ec2:StartInstances", "ec2:StopInstances"],
"Resource": "arn:aws:ec2:REGION:ACCOUNT_ID:instance/i-0123456789abcdef0"
}
]
}
Create it with the AWS CLI:
aws iam create-role \
--role-name scheduler-ec2-control \
--assume-role-policy-document file://trust.json
aws iam put-role-policy \
--role-name scheduler-ec2-control \
--policy-name ec2-start-stop \
--policy-document file://permissions.json

Step 2: Create the "stop" schedule

aws scheduler create-schedule \
--name stop-dev-instance \
--schedule-expression "cron(0 20 ? * MON-FRI *)" \
--schedule-expression-timezone "Asia/Kolkata" \
--flexible-time-window Mode=OFF \
--target '{
"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances",
"RoleArn": "arn:aws:iam::ACCOUNT_ID:role/scheduler-ec2-control",
"Input": "{\"InstanceIds\":[\"i-0123456789abcdef0\"]}"
}'
Three things worth understanding here:
  • The target ARN  arn:aws:scheduler:::aws-sdk:ec2:stopInstances  is the universal target format:  aws-sdk:<service>:<apiAction> .
  • The input is the same JSON body you would send to the EC2  StopInstances  API.
  • The timezone is set on the schedule itself, so you do not have to convert to UTC by hand and daylight saving is handled for you.

Step 3: Create the "start" schedule

Same command with different values:
aws scheduler create-schedule \
--name start-dev-instance \
--schedule-expression "cron(0 9 ? * MON-FRI *)" \
--schedule-expression-timezone "Asia/Kolkata" \
--flexible-time-window Mode=OFF \
--target '{
"Arn": "arn:aws:scheduler:::aws-sdk:ec2:startInstances",
"RoleArn": "arn:aws:iam::ACCOUNT_ID:role/scheduler-ec2-control",
"Input": "{\"InstanceIds\":[\"i-0123456789abcdef0\"]}"
}'

Prefer the console?

  1. Open Amazon EventBridge > Scheduler > Schedules and choose Create schedule.
  1. Pick Recurring schedule, choose Cron-based, enter  0 20 ? * MON-FRI * , and select your time zone.
  1. For the target, choose All APIs, search for EC2, and select StopInstances.
  1. Paste  {"InstanceIds":["i-0123456789abcdef0"]}  as the input.
  1. Choose the existing role you created above, then create the schedule.
  1. Repeat with StartInstances and the morning time.

Test it before trusting it

Create a temporary one-time schedule a few minutes from now:
aws scheduler create-schedule \
--name test-stop \
--schedule-expression "at(2026-01-15T18:30:00)" \
--schedule-expression-timezone "Asia/Kolkata" \
--flexible-time-window Mode=OFF \
--action-after-completion DELETE \
--target '{
"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances",
"RoleArn": "arn:aws:iam::ACCOUNT_ID:role/scheduler-ec2-control",
"Input": "{\"InstanceIds\":[\"i-0123456789abcdef0\"]}"
}'
Change the timestamp to a few minutes in the future. Then watch the instance state in the EC2 console. The  --action-after-completion DELETE  flag removes the one-time schedule after it runs.

Gotchas to know about

  • EBS still costs money. Stopped instances keep their volumes, so you pay for storage.
  • Public IPs change. An auto-assigned public IPv4 address is released when the instance stops. Use an Elastic IP or a DNS name if something depends on a fixed address.
  • Instance store data is lost when you stop an instance. Do not use this on instances that keep important data there.
  • Check the cron fields. EventBridge cron has six fields (minute, hour, day-of-month, month, day-of-week, year), and one of day-of-month or day-of-week must be  ? .
  • Long-running work. A job that runs past 20:00 will be cut off, so keep the stop time later than your longest batch.
  • Add a failure signal. Configure a dead-letter queue on the schedule, or an alarm on the  TargetErrorCount  metric, so you find out if a stop ever fails silently.

Scaling beyond one instance

  • Put several IDs in the  InstanceIds  array. A single call can handle multiple instances.
  • For fleets selected by tag (for example  Schedule=office-hours ), use an AWS Systems Manager Automation runbook or a small Lambda function as the target, since the EC2 Start/Stop APIs take instance IDs, not tags.
  • Manage the schedules and role as AWS CloudFormation or AWS CDK so they live in version control.

Cleanup

aws scheduler delete-schedule --name stop-dev-instance
aws scheduler delete-schedule --name start-dev-instance
aws iam delete-role-policy --role-name scheduler-ec2-control --policy-name ec2-start-stop
aws iam delete-role --role-name scheduler-ec2-control

Wrap-up

Two schedules and one least-privilege role are enough to stop paying for servers nobody is using. EventBridge Scheduler's universal targets keep it free of custom code, so there is nothing to patch or redeploy. Check the current EventBridge Scheduler and EC2 pricing pages for your Region to estimate your own savings.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article