How to let your team start EC2 instances without the AWS console
Once dev and test machines are switched off out of hours, someone will need one at 9 p.m. or on a Sunday. Here are five ways to let them turn it on themselves without handing out broad AWS access, and the question every one of them has to answer: when does it go off again?
I build CostCapper, which is the last option below, so weigh this accordingly. The first four are free and can be the right answer.
The options at a glance
| Option | Who can use it | Needs AWS sign-in | Stops it again | Effort |
|---|---|---|---|---|
| Narrow IAM permissions | People with AWS access | Yes | No | Low |
| Systems Manager runbook | People with AWS access | Yes | No | Low |
| Slack or Teams, through Amazon Q Developer | Members of a chat channel | No (chat sign-in) | No | Medium |
| Your own small web page | Whoever you let in | Your choice | If you build it | High |
| CostCapper | Anyone you allow | No (Google, Microsoft or OIDC) | Yes, when their time is up | About 15 minutes |
1. Narrow IAM permissions
Give developers a role, for example an IAM Identity Center permission set, that can only start and stop instances carrying a tag:
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Action": "ec2:DescribeInstances", "Resource": "*" },
{ "Effect": "Allow",
"Action": ["ec2:StartInstances", "ec2:StopInstances"],
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": { "StringEquals": { "aws:ResourceTag/team": "dev" } } }
]
}
Without ec2:CreateTags, they can't tag other instances to bring them into scope. If the instances have encrypted volumes, add kms:CreateGrant on the key, or starts will fail (see EC2 instance won't start?).
Good for: developers who already use the console or CLI. Watch for: it still means an AWS login, and nothing stops the instance when they're done. Late-night use tends to run until the next scheduled stop.
2. A Systems Manager Automation runbook
AWS provides a runbook, AWS-StartEC2Instance, that starts one or more instances. Run it with an AutomationAssumeRole that can start instances, and people only need permission to run that runbook, not to start instances directly. Each run is recorded in Automation's execution history.
Good for: an audit trail without granting EC2 permissions. Watch for: it's still the AWS console or CLI, a runbook form isn't friendly for non-engineers, and it doesn't stop the instance later.
3. Slack or Teams, through Amazon Q Developer in chat applications
AWS's chat integration (formerly AWS Chatbot) runs AWS CLI commands from a Slack or Microsoft Teams channel, for example @Amazon Q ec2 start-instances --instance-ids i-1234567890abcdef0. What the channel can do is limited by the IAM role you give it and by channel guardrail policies, so scope both to starting and stopping your dev instances.
Good for: teams that live in chat. Watch for: people need the instance ID, everyone in the channel has the same permissions, and stopping is again up to someone remembering.
4. Your own small web page
A Lambda function behind a URL or API Gateway, with a simple page listing machines and a Start button. It's the most flexible option and the most work: you own sign-in, who can see which machine, failed starts, encrypted volumes and the page itself. Authentication is the part to get right; an unauthenticated start URL is the version that tends to get built in an afternoon and forgotten.
The part they all leave out: switching it off again
Starting is easy. The cost is in machines left on after the person is done. If you build your own, a simple pattern is a stop-after time:
- When someone starts an instance, tag it with when it should stop, for example
stop-after=2026-11-07T23:00:00Z. - Run a small Lambda every 15 minutes with EventBridge Scheduler that stops running instances whose time has passed and removes the tag.
import boto3
from datetime import datetime, timezone
ec2 = boto3.client("ec2")
def handler(event, context):
now = datetime.now(timezone.utc)
pages = ec2.get_paginator("describe_instances").paginate(Filters=[
{"Name": "tag-key", "Values": ["stop-after"]},
{"Name": "instance-state-name", "Values": ["running"]},
])
for page in pages:
for reservation in page["Reservations"]:
for instance in reservation["Instances"]:
tags = {t["Key"]: t["Value"] for t in instance.get("Tags", [])}
due = datetime.fromisoformat(tags["stop-after"].replace("Z", "+00:00"))
if due <= now:
ec2.stop_instances(InstanceIds=[instance["InstanceId"]])
ec2.delete_tags(Resources=[instance["InstanceId"]], Tags=[{"Key": "stop-after"}])
The function needs ec2:DescribeInstances, ec2:StopInstances and ec2:DeleteTags, ideally limited to your dev instances. Two things to decide before you rely on it: what happens when two people are using the same machine (the later time should win), and how people get a warning before it stops.
5. CostCapper
A small server you launch in your own AWS account. People sign in with Google, Microsoft or any OpenID Connect provider, or with an emailed link, and see only the machines you allow. They choose how long they need, see a countdown, and get an email 15 minutes before the machine stops. With several people on one machine, it stays on until the last person's time is up. Its IAM role can only describe, start and stop machines, and it's free for up to 3 machines.
Good for: teams where people who don't use the AWS console need machines at irregular hours. Watch for: it's paid above 3 machines, and it's a new product.
Short version: developers who already use AWS, give them a narrow IAM role. A team in Slack or Teams, try Amazon Q Developer in chat. Whatever you choose, decide how the machine gets switched off again, because that's where the money goes.