0

由于各种原因、硬件问题、维护等,亚马逊有时会回收(关闭并重新创建)EC2 实例。当这种情况发生时,您如何得到通知?我已经尝试了几个状态检查警报,但它们似乎没有被触发。而且这种情况很难重现,因为由亚马逊决定何时回收。

4

1 回答 1

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 me@example.com

# 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
于 2012-12-14T00:53:38.803 回答