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
Open the Amazon SNS console at https://console.amazonaws.cn/sns/v3/home
. -
In the navigation pane, choose Topics.
-
Choose Create topic.
-
For Type, choose Standard.
-
For Name, enter a name for your topic.
-
Choose Create topic.
-
Choose Create subscription.
-
For Protocol, choose Email.
-
For Endpoint, enter the email address that receives the notifications.
-
Choose Create subscription.
-
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
Open the Amazon EventBridge console at https://console.amazonaws.cn/events/
. -
Choose Create rule.
-
For Name, enter a name for your rule.
-
For Rule type, choose Rule with an event pattern.
-
Choose Next.
-
For Event pattern, do the following:
-
For Event source, choose Amazon Web Services.
-
For Amazon Web Service, choose EC2.
-
For Event type, choose EC2 Instance State-change Notification.
-
By default, we send notifications for any state change for any instance. If you prefer, you can select specific states or specific instances.
-
-
Choose Next.
-
Specify a target as follows:
-
For Target types, choose Amazon Web Service.
-
For Select a target, choose SNS topic.
-
For Topic, choose the SNS topic that you created in the previous procedure.
-
-
Choose Next.
-
(Optional) Add tags to your rule.
-
Choose Next.
-
Choose Create rule.
-
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.