How can I receive notifications for scheduled events for my EC2 instance using CloudWatch Events?

Last updated: 2019-05-08

I want to receive notifications from Amazon CloudWatch Events when there's a scheduled event for my Amazon Elastic Compute Cloud (Amazon EC2) instance. How can I do that?

Short Description

You can create a CloudWatch Events rule to trigger on a scheduled event for your EC2 instance. Then, you can configure Amazon Simple Notification Service (Amazon SNS) notifications for events that match your event pattern. You can also configure further processing through AWS Lambda.

Resolution

Important: Before you begin, be sure that you have an SNS topic for notifications. If you don't have one, create a new SNS topic and subscribe to it.

Create a CloudWatch Events rule that triggers on an event using the CloudWatch console:

1.    For Event Pattern, choose Build Event pattern to match events by service.

2.    For Service Name, choose Health.

3.    For Event Type, choose Specific Health events.

4.    Choose Specific service(s), and then choose EC2.

5.    Choose Specific event type category(s), and then choose scheduledChange.

6.    (Optional) To be notified about a specific instance instead of all instances, choose Specific resource(s), and then choose the instance's ID.

These settings create the following event pattern.

Note: You can also create your event pattern by copying and pasting the following code as your rule. After you choose Create Rule, choose Edit in the Event Pattern Preview section. Insert the code below, choose Save, and then proceed to create an SNS target.

{
  "source": [
    "aws.health"
  ],
  "detail-type": [
    "AWS Health Event"
  ],
  "detail": {
    "service": [
      "EC2"
    ],
    "eventTypeCategory": [
      "scheduledChange"
    ]
  }
}

Select your SNS target:

1.    Choose Add Target.

2.    For the target, choose SNS topic.

3.    For Topic, choose the SNS topic that you want to use for notifications.

4.    Choose Configure details.

5.    Configure additional settings as necessary, such as further event processing with Lambda.

6.    Choose Create Rule.

Note: The following example shows what a scheduled event looks like when it's pushed to CloudWatch Events.

{
  "version": "0",
  "id": "7fb65329-1628-4cf3-a740-95fg457h1402",
  "detail-type": "AWS Health Event",
  "source": "aws.health",
  "account": "123456789101",
  "time": "2016-06-05T06:27:57Z",
  "region": "us-east-1",
  "resources": ["i-12345678"],
  "detail": {
    "eventArn": "arn:aws:health:region::event/id",
    "service": "EC2",
    "eventTypeCode": "AWS_EC2_DEDICATED_HOST_NETWORK_MAINTENANCE_SCHEDULED",
    "eventTypeCategory": "scheduledChange",
    "startTime": "Sat, 05 Jun 2016 15:10:09 GMT",
    "eventDescription": [{
      "language": "en_US",
      "latestDescription": "A description of the event will be provided here"
    }],
    "affectedEntities": [{
      "entityValue": "i-12345678",
      "tags": {
        "stage": "prod",
        "app": "my-app"
      }
    }]
  }
}

Did this article help you?

Anything we could improve?


Need more help?