State change events for your instances - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

State change events for your instances

Amazon EC2 sends an EC2 Instance State-change Notification event to Amazon EventBridge when the state of an instance changes.

The following is example data for this event. In this example, the instance entered the pending state.

{ "id":"7bf73129-1428-4cd3-a780-95db273d1602", "detail-type":"EC2 Instance State-change Notification", "source":"aws.ec2", "account":"123456789012", "time":"2021-11-11T21:29:54Z", "region":"us-east-1", "resources":[ "arn:aws-cn:ec2:us-east-1:123456789012:instance/i-abcd1111" ], "detail":{ "instance-id":"i-abcd1111", "state":"pending" } }

The possible values for state are:

  • pending

  • running

  • stopping

  • stopped

  • shutting-down

  • terminated

When you launch or start an instance, it enters the pending state and then the running state. When you stop an instance, it enters the stopping state and then the stopped state. When you terminate an instance, it enters the shutting-down state and then the terminated state.

Get an email notification when an instance changes state

To receive email notifications when your instance changes state, create an Amazon SNS topic and then create an EventBridge rule for the EC2 Instance State-change Notification event.

To create an SNS topic

  1. Open the Amazon SNS console at https://console.amazonaws.cn/sns/v3/home.

  2. In the navigation pane, choose Topics.

  3. Choose Create topic.

  4. For Type, choose Standard.

  5. For Name, enter a name for your topic.

  6. Choose Create topic.

  7. Choose Create subscription.

  8. For Protocol, choose Email.

  9. For Endpoint, enter the email address that receives the notifications.

  10. Choose Create subscription.

  11. You'll receive an email message with the following subject line: Amazon Notification - Subscription Confirmation. Follow the directions to confirm your subscription.

To create an EventBridge rule

  1. Open the Amazon EventBridge console at https://console.amazonaws.cn/events/.

  2. Choose Create rule.

  3. For Name, enter a name for your rule.

  4. For Rule type, choose Rule with an event pattern.

  5. Choose Next.

  6. For Event pattern, do the following:

    1. For Event source, choose Amazon Web Services.

    2. For Amazon Web Service, choose EC2.

    3. For Event type, choose EC2 Instance State-change Notification.

    4. By default, we send notifications for any state change for any instance. If you prefer, you can select specific states or specific instances.

  7. Choose Next.

  8. Specify a target as follows:

    1. For Target types, choose Amazon Web Service.

    2. For Select a target, choose SNS topic.

    3. For Topic, choose the SNS topic that you created in the previous procedure.

  9. Choose Next.

  10. (Optional) Add tags to your rule.

  11. Choose Next.

  12. Choose Create rule.

  13. To test your rule, initiate a state change. For example, start a stopped instance, stop a running instance, or launch an instance. You'll receive email messages with the following subject line: Amazon Notification Message. The body of the email contains the event data.