← All guides

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

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:

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:

EventResultWhy
r6g.8xlargetruelarger than 4xlarge
c7i.metal-24xltruebare metal is not in the small list
g4dn.xlargetrueGPU family, matched by prefix
p5.48xlargetrueGPU family and large
m5.2xlargefalsein the small list
t3.microfalsein the small list
launch template, no typetruethe type is in the template, so the rule alerts anyway
r6g.8xlarge, call failedfalseerrorCode 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:

Where Outseen fits

Outseen starts from the same CloudTrail and EventBridge events as this guide, then adds the parts you'd otherwise build yourself:

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.