How to get alerted when someone launches an expensive EC2 instance
By the Outseen team ·
Someone on your team launches a large instance to test something, and forgets it. You find out from the bill. AWS Budgets won't help much: it works on billing data, which AWS updates at least once a day, and it alerts on totals, not on the launch itself.
AWS already has the parts for a launch alert. CloudTrail records every RunInstances call, EventBridge can match it, and SNS can email it. This guide builds that, with a filter so you only hear about big instances, and tests it without launching anything. Then it covers what this setup still can't do.
Before you start
- A CloudTrail trail with logging turned on. EventBridge only receives "AWS API Call via CloudTrail" events when one exists.
- The AWS CLI, with permission to create SNS topics and EventBridge rules.
- The region you want to watch. The examples use us-east-1 and the placeholder account 111122223333: replace both.
1. Create an SNS topic and subscribe to it
aws sns create-topic --name ec2-launch-alerts --region us-east-1 aws sns subscribe --region us-east-1 \ --topic-arn arn:aws:sns:us-east-1:111122223333:ec2-launch-alerts \ --protocol email \ --notification-endpoint [email protected]
AWS emails a confirmation link. Click it, or nothing will be delivered.
2. Let EventBridge publish to the topic
Save this as topic-policy.json. The condition limits it to the one rule you're about to create.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowEventBridgeRule",
"Effect": "Allow",
"Principal": { "Service": "events.amazonaws.com" },
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-east-1:111122223333:ec2-launch-alerts",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "arn:aws:events:us-east-1:111122223333:rule/ec2-expensive-launch"
}
}
}
]
}aws sns set-topic-attributes --region us-east-1 \ --topic-arn arn:aws:sns:us-east-1:111122223333:ec2-launch-alerts \ --attribute-name Policy \ --attribute-value file://topic-policy.json
This replaces the topic's default policy. If the topic already has a policy you rely on, add the statement to it instead.
3. Write the event pattern
Save this as pattern.json:
{
"source": ["aws.ec2"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["ec2.amazonaws.com"],
"eventName": ["RunInstances"],
"errorCode": [{ "exists": false }],
"requestParameters": {
"$or": [
{ "instanceType": [
{ "anything-but": { "wildcard": [
"*.nano", "*.micro", "*.small", "*.medium",
"*.large", "*.xlarge", "*.2xlarge", "*.4xlarge"
] } },
{ "prefix": "g" },
{ "prefix": "p" }
] },
{ "instanceType": [{ "exists": false }] }
]
}
}
}What each part does:
- source, detail-type and eventName: only successful RunInstances calls recorded by CloudTrail.
- errorCode does not exist: failed calls, including dry runs, are ignored.
- The first instanceType branch matches any type that isn't in the small list, so 8xlarge and up, and bare metal. It also matches the g and p GPU families at any size.
- The second branch matches calls with no instanceType at all. That happens when the launch uses a launch template, where the type lives in the template. Without it, those launches would never alert.
Adjust the small list to your own idea of expensive. Instance size is only a proxy for price, which is the first weakness of this setup.
4. Create the rule and a readable email
Without an input transformer, SNS emails the raw JSON event. This one turns it into a few lines. Save it as targets.json:
[
{
"Id": "email",
"Arn": "arn:aws:sns:us-east-1:111122223333:ec2-launch-alerts",
"InputTransformer": {
"InputPathsMap": {
"who": "$.detail.userIdentity.arn",
"type": "$.detail.requestParameters.instanceType",
"count": "$.detail.requestParameters.instancesSet.items[0].maxCount",
"instance": "$.detail.responseElements.instancesSet.items[0].instanceId",
"region": "$.region",
"account": "$.account",
"time": "$.time"
},
"InputTemplate": "\"EC2 launch in <region>, account <account>\"\n\"Launched by: <who>\"\n\"Instance type: <type>\"\n\"Instances requested: up to <count>\"\n\"First instance: <instance>\"\n\"Time: <time>\""
}
}
]aws events put-rule --region us-east-1 \ --name ec2-expensive-launch \ --event-pattern file://pattern.json aws events put-targets --region us-east-1 \ --rule ec2-expensive-launch \ --targets file://targets.json
If a field is missing from the event, such as the instance type on a launch-template launch, EventBridge doesn't create that variable, so don't rely on that line of the email for those launches.
5. Test it without launching anything
A dry-run launch won't work, because the pattern ignores failed calls. Test the pattern directly instead. Save this as test-event.json:
{
"id": "1",
"account": "111122223333",
"source": "aws.ec2",
"time": "2026-11-01T10:00:00Z",
"region": "us-east-1",
"resources": [],
"detail-type": "AWS API Call via CloudTrail",
"detail": {
"eventSource": "ec2.amazonaws.com",
"eventName": "RunInstances",
"requestParameters": { "instanceType": "r6g.8xlarge" }
}
}aws events test-event-pattern --region us-east-1 \ --event-pattern file://pattern.json \ --event file://test-event.json
It returns { "Result": true }. We ran the pattern against these events:
| Event | Result | Why |
|---|---|---|
| r6g.8xlarge | true | larger than 4xlarge |
| c7i.metal-24xl | true | bare metal is not in the small list |
| g4dn.xlarge | true | GPU family, matched by prefix |
| p5.48xlarge | true | GPU family and large |
| m5.2xlarge | false | in the small list |
| t3.micro | false | in the small list |
| launch template, no type | true | the type is in the template, so the rule alerts anyway |
| r6g.8xlarge, call failed | false | errorCode is set |
When the rule matches a real launch, the email usually arrives within minutes: CloudTrail has to record the call before EventBridge sees it.
6. Repeat for every region
The rule only sees launches in its own region. Repeat steps 1 to 4 in each region your team uses, or create the topic once and add a rule in each region that forwards matching events to the bus where the SNS target lives.
What this setup doesn't do
It names the instance type, not the price
An alert that says r6g.8xlarge still leaves someone to look up what that costs in that region, for that operating system, with those EBS volumes, times the number of instances. Doing it automatically means a Lambda function between the rule and SNS that calls the AWS Price List API and handles all of those dimensions.
Instance size is a rough proxy
Twenty m5.2xlarge instances in one call slip past this filter without an alert, while a single g4dn.xlarge triggers one. Launches from a launch template alert without a type, so someone has to open the template to see what was launched.
One rule per region
CloudTrail sends each event to the default event bus in the region where the call happened. A rule in us-east-1 never sees a launch in eu-west-1, which is often exactly the forgotten instance. You need the topic policy, rule and target in every region your team could use, or rules that forward to a central bus.
It goes to a list, not to the person who decides
Everyone on the topic gets every alert. Nothing routes a launch in the data team's account to the data team's lead, and nothing records that anyone looked at it.
No approval and no escalation
The email can't be answered with Approve or Reject, and if the one person who reads it is on holiday, the instance runs until the bill. Building that needs state, a way to reply (Slack interactivity or signed email links), timers for escalation, and somewhere to keep the decisions.
Only EC2, and only RunInstances
RDS (CreateDBInstance), NAT gateways (CreateNatGateway), EKS node groups (CreateNodegroup) and SageMaker endpoints (CreateEndpoint) each need their own pattern and their own pricing logic. Instances launched through EC2 Fleet (CreateFleet), which Karpenter uses, don't go through RunInstances at all.
Auto Scaling groups also launch through launch templates, so the second branch of the pattern can alert on scale-outs. If that gets noisy, the usual fix is to filter on who made the call, at the cost of a more complex rule.
When the DIY rule is enough
Keep it, and don't pay for anything else, if:
- You have one AWS account and use one or two regions.
- The same few people would read the alert and make the call anyway.
- Knowing the instance type is enough for you to judge the cost.
- You're happy to maintain the rule as instance families and your regions change.
Where Outseen fits
Outseen starts from the same CloudTrail and EventBridge events as this guide, then adds the parts you'd otherwise build yourself:
- One CloudFormation stack (or a StackSet for every region) creates the EventBridge rules, forwarding RunInstances and the create, start and resize calls for the services it prices.
- Each launch gets a cost range from live regional on-demand prices, before Savings Plans, Reserved Instances or discounts, with a list of what the estimate leaves out.
- Your policy decides who approves what, by team, account, region or resource type, with up to three escalation levels. Each approver has 4 hours by default.
- Approvers get the cost and who launched it in Slack, Jira or email, and can Approve, Reject or Request Downsize.
- If you opt in, rejected or timed-out EC2 and RDS resources that carry a tag you chose are stopped. Nothing is ever terminated or deleted.
- Auto Scaling, EKS and Spot scale-outs are recorded but not sent for approval, so they don't flood your approvers.
- If event delivery breaks, a daily CloudTrail check finds launches that never arrived and emails your admins.
It prices EC2, EBS, RDS, Aurora, S3, NAT gateways, load balancers, ElastiCache, Redshift, EKS and SageMaker. Like the DIY rule, it doesn't yet see launches through EC2 Fleet, and it doesn't price data transfer or request-based services such as Lambda. The role it uses is read-only, can't write tags, and stops tagged resources only if you turn that on. The security page has the exact policies, and the FAQ has the rest.
Already using AWS Budgets or Infracost? See how Outseen compares with AWS Budgets and Infracost. And if NAT gateways are what's growing on your bill, see how to find and cut NAT gateway costs. The same kind of rule can catch new databases on old engine versions: see RDS Extended Support costs.