Automating Notifications for Future-Dated Amazon EC2 Capacity Reservation State Changes

1 day ago 3
News Banner

Looking for an Interim or Fractional CTO to support your business?

Read more

This post is written by Ballu Singh, Principal Solutions Architect at AWS, Sandeep Rohilla, Senior Solutions Architect at AWS and Pranjal Gururani, Senior Solutions Architect at AWS.

AWS customers are able to proactively reserve future-dated Amazon EC2 On-Demand Capacity Reservations (known as future-dated CRs) to get capacity assurance for workloads and events. Because reservations can be created weeks in advance, customers are able to ensure that they can monitor their real-time status. Future-dated CRs can transition through various state of a Capacity Reservation, based on capacity availability. Over the course of several weeks, the status of a reservation might only change one or two times. Even with the low frequency of changes, most customers don’t want to manually poll the state of their reservations, instead they want to be proactively notified when something changes.

Amazon EventBridge is a serverless event bus service that facilitates the routing of events and EventBridge rules establish how events are processed, allowing you to filter events and route them to one or more targets for action. Amazon Simple Notification Service (SNS) is a fully managed messaging service that enables you to send messages or notifications to a variety of endpoints, facilitating scalable, and decoupled communication between different components of your application or with end-users.

In this blog post, we guide you through the process of automating notifications for future-dated CR state changes using AWS services such as Amazon EventBridge and Amazon Simple Notification Service (SNS).

Pre-requisites

  • Existing future-dated Capacity Reservation. To learn how to create future-dated CRs, visit our blog post here.
  • IAM access to create Amazon EventBridge rules
  • IAM access to create Amazon SNS topic and subscription

Architecture

Amazon EC2 continuously monitors the state of your future dated CRs and sends events to Amazon EventBridge when CR states change. Using Amazon EventBridge, you can create rules that trigger notifications through Amazon SNS in response to these events. Amazon SNS then pushes these notifications to a variety of supported endpoint types such as Amazon Data Firehose, Amazon Simple Queue Service (SQS), AWS Lambda, HTTP, email, mobile push notifications, and mobile text messages (SMS). In our example, we will send notification to our email address.

Send notification to email address

Walkthrough

To automate the notification process for future-dated CR state changes, we will use the following AWS services:

  1. Amazon Simple Notification Service (SNS): We will use SNS to send email notifications to the designated recipients.
  2. Amazon EventBridge: We will create an EventBridge rule to capture the state change events of future-dated CRs.

AWS Console Walkthrough

Step 1: Set Up Amazon SNS Topics and Subscriptions

  • Create a new topic for future-dated CR state change notifications.
    • Navigate to Amazon SNS console. On the Topics page, choose Create topic
    • In the Details section, for Type, choose Standard and enter the name of Topic (ex: Subscriber)

CreateTopic

    • Choose rest of details as is. Choose Create topic.
  • Create a subscription for the desired recipients, such as email addresses to receive the notifications.
    • Navigate to Amazon SNS console. In the left navigation pane, choose Subscriptions. Choose Create subscription.
    • On the Create subscription page, in the Details section, for Topic ARN, choose the Amazon Resource Name (ARN) of a topic enter topic ARN noted above. For Protocol, choose Email/Email-JSON
    • For Endpoint, enter your email address. Keep rest of details as is.

create subscription for the desired recipients

    • Choose Create subscription
    • Navigate to your email and choose Confirm subscription in the email from Amazon SNS.

Step 2: Create an Amazon EventBridge Rule

  • Next open the Amazon EventBridge console and navigate to the Rules
  • Click on Create rule and provide a name (ex: EC2CapacityReservationStateChange) and description for the rule. Keep all other setting as it is. Select
  • For Event source, choose AWS events or EventBridge partner events.
  • In the Creation method section, for Method, choose Use pattern form.
  • For Event source, choose AWS services. Under AWS Service, choose EC2 and then choose EC2 Capacity Reservation.
  • Optionally, you can narrow down the state and reservation ID you want to be alerted for by selecting Specific Capacity Reservation State and Specific Capacity reservation ID. Select Next.

Create an amazon eventbridge rule

  • In the Target section, under Target Type, select AWS Service.
  • For Select Target, choose SNS topic, under Topic, select SNS Topic you created in Step 1. Select
  • On Configure Tags page, select Next.
  • On Review and create page, select Create Rule.

CloudFormation Walkthrough

To simplify the setup process and make it easier for you to implement the automated notification solution, we have provided a CloudFormation template. This template automates the creation of the necessary Amazon EventBridge rule and Amazon SNS topic, along with the required configurations and permissions.

  1. Download yaml sample template.
  2. Navigate to AWS CloudFormation console and click on Create stack.
  3. Choose Upload a template file and select the downloaded template. Choose Next
  4. Provide a name for the stack under Stack Name. For CapacityReservationId, enter ID of the EC2 Capacity Reservation to monitor, (e.g., cr-1234567890abcdef0), for EmailAddress, enter email address you want to subscribe to the SNS topic, and for MonitoredStates enter comma-separated list of Capacity Reservation states to monitor (e.g. failed, expired, cancelled, pending). Choose Next

CloudFormation walkthrough

5. On Configure stack options, keep defaults. Choose

6. On Review and create page, choose

Clean up

To avoid ongoing charges, clean up your environment, by following these steps to delete the resources you created by following this blog, if they are no longer needed:

If you followed setup for AWS Console, please follow the below steps:

  1. Delete the Amazon EventBridge Rule
    1. Navigate to Amazon EventBridge console and choose to the Rules from left pane.
    2. Choose the rule you created earlier and click on Delete.
    3. Confirm the deletion by clicking Delete in the confirmation dialog.
  2. Delete the Amazon SNS Topic and Subscriptions
    1. Navigate to Amazon SNS console and navigate to the Topics from left pane.
    2. Choose the topic you created earlier and click on Delete.
    3. Confirm the deletion by clicking Delete in the confirmation dialog.

If you created any subscriptions for the topic (e.g., email or SMS), they will be automatically deleted along with the topic.

If you deployed CloudFormation template, please follow the below steps:

Conclusion

In this blog post we walked you through setting up an EventBridge rule to capture the state change events of your future-dated CRs and configure SNS to send notifications to the designated recipients. This automated approach eliminates the need for manual monitoring and ensures that you stay informed about the status of your capacity reservations.

By proactively managing your future-dated CRs through automated notifications, you can make informed decisions, adjust your reservation plans if need, and take corrective actions to ensure you have the necessary resources available for your critical events.

This solution enhances your operational efficiency, reduces the risk of capacity shortages, and allows you to focus on other important aspects of your business.

We encourage you to implement this automated notification system for your future-dated Amazon EC2 On-Demand Capacity Reservations and experience the benefits of streamlined monitoring and proactive capacity management.

Read Entire Article