2012-12-13 53 views
0

由於各種原因,硬件問題,維護等,亞馬遜有時會回收(關閉並重新創建)EC2實例。發生這種情況時,您會如何得到通知?我已經嘗試了幾種狀態檢查報警,並且他們似乎沒有被觸發。而且這種情況很難再現,因爲亞馬遜決定何時回收。如何在EC2實例回收時得到通知?

回答

2

您可以創建單個實例的自動縮放組(min = 1,max = 1),然後訂閱其自動縮放事件。這是我用於此目的的Bash腳本的一部分(它假定您已安裝AWS命令行工具)。

# Create SNS topic and email subscription to receive notifications 
SNS=$(sns-create-topic AWS-MyApp) 
sns-subscribe $SNS --protocol email --endpoint [email protected] 

# Create launch configuration 
as-create-launch-config app-as-cfg_sm --image-id ami-05dd5c6c --instance-type m1.small --group app-sg --key myapp-prod-key 

# Make an autoscaling group of one instance with the launch config 
as-create-auto-scaling-group app-as-grp --launch-configuration app-as-cfg_sm --min-size 1 --max-size 1 --default-cooldown 120 --grace-period 300 --tag "k=Name, v=MyApp-Autoscale, p=true" 

# Subscribe to all the autoscaling events so I know what's going on. 
as-put-notification-configuration --topic-arn $SNS --auto-scaling-group 'app-as-grp' --notification-types autoscaling:EC2_INSTANCE_LAUNCH, autoscaling:EC2_INSTANCE_TERMINATE, autoscaling:EC2_INSTANCE_TERMINATE_ERROR, autoscaling:EC2_INSTANCE_LAUNCH_ERROR