| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
You can set up Auto Scaling to send notifications to you as instances are terminated and launched. When the Spot market price goes up and your bid price falls below it, Amazon EC2 terminates the instances that were launched based on that bid price. If your Spot Instances are terminated, Auto Scaling will try to submit your bid and launch replacement instances and to ensure the capacity you specified for your Auto Scaling group. You can set up Auto Scaling to notify you when instance launch or termination events occur.
There are two ways to get notifications for Spot Instances:
Auto Scaling
AWS SDK Sample Code Tool
Spot Notifications Sample in AWS Java SDK
You can also use the AWS Java SDK to develop applications that monitor your Spot Instance usage in ways that are customized to your use case. The Spot Notifications sample application is a Java application that demonstrates techniques for monitoring Amazon EC2 instance status, Spot Instance requests, and Spot price fluctuations. The application is documented and freely available for download at How to Track Spot Instance Activity with the Spot-Notifications Sample Application. You are free to adapt the application for your own purposes, or use it as a guide in developing your own application for monitoring Spot Instances. For more information, go to the AWS SDK for Java.
Configuring Auto Scaling groups to send notifications about your Spot Instances
In this portion of the walkthrough, you learn how to set up Amazon SNS to send email notifications.
To do this, you need the following:
An Amazon Resource Name (ARN). You generate an ARN when you create an Amazon Simple Notification Service (Amazon SNS) topic. A topic is a communication channel to send messages and subscribe to notifications. It provides an access point for publishers and subscribers to communicate with each other. An endpoint, such as an email address, must be subscribed to the topic so the endpoint can receive messages published to the topic. To create a topic, go to Create a Topic in the Amazon Simple Notification Service Getting Started Guide.
An Auto Scaling Group. Use the Auto Scaling group that you created earlier in this walkthrough.
A notification configuration. You configure an Auto Scaling group to send notifications when specified events take
place by calling the as-put-notification-configuration CLI command or the PutNotificationConfiguration API action.
We will discuss the steps in setting up a notification configuration later in this section. For more information about the command,
go to PutNotificationConfiguration
in the Auto Scaling API Reference.
A list of Auto Scaling notification types. These notification types are the events that will cause the notification to be sent.
Set Up Notifications Using Auto Scaling
After you've created your Amazon SNS topic and you have the ARN, you are ready to set up the notification configuration. (To create a topic, go to Create a Topic in the Amazon Simple Notification Service Getting Started Guide.)
To configure your Auto Scaling group to send notifications when specified events take place, use the as-put-notification-configuration
CLI command.
The as-put-notification-configuration command takes the following arguments:
as-put-notification-configuration
AutoScalingGroupName --notification-types value --topic-arn topic-ARN [General Options]
You need to specify the Auto Scaling group name, the ARN, and the notification types.
For this example, specify:
Auto Scaling group name: spotasg
Specify the Auto Scaling group that you want to get notifications about. In this walkthrough, you want Auto Scaling to notify you when instances are launched and terminated for the spotasg Auto Scaling group.
ARN:arn:placeholder:MyTopic
Note
ARNs are unique identifiers for Amazon Web Services (AWS) resources. Replace the ARN placeholder with your ARN.
Notification types: autoscaling:EC2_Instance_Launch, autoscaling:EC2_Instance_Terminate
The notification types are the events you want Auto Scaling to send you e-mail about.
Open a command prompt and enter the as-put-notification-configuration command.
as-put-notification-configuration spotasg--topic-arn arn:placeholder:MyTopic --notification-types autoscaling:EC2_INSTANCE_LAUNCH, autoscaling:EC2_INSTANCE_TERMINATE
Auto Scaling returns the following:
OK-Put Notification Configuration
You now have a notification configuration that sends a notification to the endpoint subscribed
in the arn:placeholder:MyTopic ARN whenever instances are launched or terminated.
Verify the notification configuration.
To verify the notification actions associated with your Auto Scaling group when specified events take place, use as-describe-notification-configurations.
The as-describe-notification-configurations command takes the following arguments:
as-describe-notification-configurations
[
--auto-scaling-groups value[,value...]] [--maxrecords value] [General Options]
If you specify the Auto Scaling group, this command returns a full list of all notification configuration for the Auto Scaling group listed. If you don't provide an Auto Scaling group name,
the service returns the full details of all Auto Scaling groups. The command also returns a token if there are more pages to retrieve. To get the next page, call this action
again with the returned token as the next-token argument. For this walkthrough, specify:
Auto Scaling group name: spotasg
Open a command prompt and enter the as-describe-notification-configurations command.
as-describe-notification-configurations --auto-scaling-groups spotasg -headers
Auto Scaling returns the following:
NOTIFICATION-CONFIG GROUP-NAME TOPIC-ARN NOTIFICATION-TYPE-NAME NOTIFICATION-CONFIG spotasg arn:placeholder:spotasg autoscaling:EC2_INSTANCE_LAUNCH NOTIFICATION-CONFIG spotasg arn:placeholder:spotasg autoscaling:EC2_INSTANCE_TERMINATE
You have confirmed that you have a notification configuration set up for the spotasg Auto Scaling group.
When Auto Scaling launches instances to reach or maintain desired capacity, as specified in your Auto Scaling group, SNS sends a
notification to your email address with information about the instances. You can check your email Inbox for this information,
then run as-describe-auto-scaling-group to get information about current instances in the Auto Scaling
group and confirm that the instances listed in your email actually exist.
What do you want to do next?