缩减规模时EC2竞价型实例终止通知 [英] EC2 spot instance termination notice when downscaling

查看:88
本文介绍了缩减规模时EC2竞价型实例终止通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我的竞价型实例计划终止时,我都需要运行清理脚本。我有两个终止的原因:

I need to run a clean up script every time my spot instance is scheduled for termination. I have two reasons for termination:


  1. 现货实例的价格超出了我的出价

  2. 通过缩放自动伸缩组的策略(基于5分钟内平均群集cpu使用率,随机实例将终止)。

我确实喜欢我在博客中找到了以下简单脚本。它涵盖了第一种情况,在关机前给了我2分钟的清理时间。

I did like the simple script below I found on this blog. It covers first case and gives me 2 minutes to clean up before shutdown.

是否有一种简单的方法可以让第二分钟收到2分钟的通知?

Is there an easy way to get such 2-minute notification for second case?

是否可以通过相同的网址获得警告?

May be the warning will be available via same url?

#!/bin/bash
while true
  do
    if [ -z $(curl -Is http://169.254.169.254/latest/meta-data/spot/termination-time | head -1 | grep 404 | cut -d \  -f 2) ]
      then
        logger "Running shutdown hook."
        # Call your shutdown script here.
        break
      else
        # Spot instance not yet marked for termination.
        sleep 5
    fi
  done


推荐答案

自动缩放挂钩允许您可以创建一个事件通知,说明实例将被终止(或启动)。

Auto Scaling Hooks allow you to create an event notification that an instance is going to be terminated (or launched).

好处是:您有更多的时间。默认值为60分钟,您可以发送心跳消息以延长时间,也可以在清理完成后通知服务。如果您不响应,则该事件将超时并反正结束。

The up-side: you get a lot more time. The default is 60 minutes, and you can send a heartbeat message to extend the time, or you can notify the service when your cleanup is done. If you don't respond, the event times out and finishes anyway.

不利的一面是:通知不会发送到实例本身,因为现货终止警告。他们去SNS或SQS。您必须为实例订阅通知(例如,在实例启动时为每个实例订阅SNS主题),或者需要滚动自己的系统来管理消息并与实例进行通信。

The down-side: the notifications don't go to the instance itself, as the spot termination warnings do. They go to SNS or SQS. You'll either have to subscribe the instance to the notifications (subscribe each instance to the SNS topic on instance startup, for example) or you'll need to roll your own system to manage the messages and communicate with the instances.

这篇关于缩减规模时EC2竞价型实例终止通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆