使用playbook更新Auto Scaling的疑惑解析

前一段在试用Ansible Playbook对AWS Auto Scaling Group Policy做更新操作时,我发现通过Ansible模块ec2_scaling_policy新建的Auto Scaling Group Policy的AWS输出参数和通过AWS Web Console建立的Auto Scaling Group Policy输出有所不同。
具体情况如下:
通过ansible



通过AWS Web Console


根据两种操作后的变更效果,我发现EstimatedInstanceWarmup和Cooldown代表的意思没有明显的区别。于是乎,我从新通过AWS Web Console进行了如上操作,此次仔细查看了面板上的各个描述,发现了如下内容。
当我们默认创建Scaling Policy时,会打开如下窗口:

在窗口左下角,有这么一行字“Create a simple scaling policy”,我们点击它,窗口的参数会变成如下:

这时,我就发现了差异所在。
对于这个地方的差异,我不是很清楚,于是就查阅AWS Doc。
内容如下:

Scaling Policy Types
When you create a scaling policy, you must specify its policy type. The policy type determines how the scaling action is performed. Auto Scaling supports the following policy types:
* Simple scaling—Increase or decrease the current capacity of the group based on a single scaling adjustment.
* Step scaling—Increase or decrease the current capacity of the group based on a set of scaling adjustments, known as step adjustments, that vary based on the size of the alarm breach.
Simple Scaling Policies
After a scaling activity is started, the policy must wait for the scaling activity or health check replacement to complete and the cooldown period to expire before it can respond to additional alarms. Cooldown periods help to prevent Auto Scaling from initiating additional scaling activities before the effects of previous activities are visible. You can use the default cooldown period associated with your Auto Scaling group, or you can override the default by specifying a cooldown period for your policy. For more information, see Understanding Auto Scaling Cooldowns.
Note that Auto Scaling originally supported only this type of scaling policy. If you created your scaling policy before policy types were introduced, your policy is treated as a simple scaling policy.

Step Scaling Policies
After a scaling activity is started, the policy continues to respond to additional alarms, even while a scaling activity or health check replacement is in progress. Therefore, all alarms that are breached are evaluated by Auto Scaling as it receives the alarm messages. If you are creating a policy to scale out, you can specify the estimated warm-up time that it will take for a newly launched instance to be ready to contribute to the aggregated metrics. For more information, see Instance Warmup.
- Note
- Cooldown periods are not supported for step scaling policies. Therefore, you can't specify a cooldown period for these policies and the default cooldown period for the group doesn't apply.

We recommend that you use step scaling policies even if you have a single step adjustment, because we continuously evaluate alarms and do not lock the group during scaling activities or health check replacements.
参考链接

根据描述,我在和最初的输出进行对比,可以发现ansible的ec2_scaling_policy模块使用的还是旧的扩展策略类型(即简单扩展策略)。这时,我再去看Cloudformation中资源类型Auto Scaling Policy(AWS::AutoScaling::ScalingPolicy),发现它对扩展策略类型的属性支持也是简单扩展策略。
AWS Cloudformation资源类型 AWS::AutoScaling::ScalingPolicy

{
   "Type" : "AWS::AutoScaling::ScalingPolicy",
   "Properties" : {
      "AdjustmentType" : String,
      "AutoScalingGroupName" : String,
      "Cooldown" : String,    # 注意
      "MinAdjustmentStep" : Integer,
      "ScalingAdjustment" : String
   }
} 

参考链接

我留意了下ansible的官方文档,它声明了在使用ec2_scaling_policy模块时的需求,内容如下:

ec2_scaling_policy - Create or delete AWS scaling policies for Autoscaling groups
New in version 1.6.

    - Synopsis
    - Requirements
    - Options
    - Examples
    - Notes
    - This is a Core Module

Synopsis
    Can create or delete scaling policies for autoscaling groups Referenced autoscaling groups must already exist

Requirements
    - python >= 2.6    # 注意
    - boto

参考链接
ansible对aws的操作是通过aws的boto实现的。ansible不支持,那就说明是boto不支持。通过查看boto中对Auto Scaling Policy操作的类,我发现boto确实不支持新的步进扩展策略,仅支持简单扩展策略。
官方文档描述如下:

class boto.ec2.autoscale.policy.ScalingPolicy(connection=None, **kwargs)
    Scaling Policy
    
    Parameters: 
        name (str) – Name of scaling policy.
        adjustment_type (str) – Specifies the type of adjustment. Valid values are ChangeInCapacity, ExactCapacity and PercentChangeInCapacity.
        as_name (str or int) – Name or ARN of the Auto Scaling Group.
        scaling_adjustment (int) – Value of adjustment (type specified in adjustment_type).
        min_adjustment_step (int) – Value of min adjustment step required to apply the scaling policy (only make sense when use PercentChangeInCapacity as adjustment_type.).
        cooldown (int) – Time (in seconds) before Alarm related Scaling Activities can start after the previous Scaling Activity ends.    # 注意

参考链接
由于,我平时都使用的是boto3.接着,我就又查看了boto3的对应类,发现在boto3中已经增加了对步进扩展策略的操作支持。

Request Syntax

response = client.put_scaling_policy(
    AutoScalingGroupName='string',
    PolicyName='string',
    PolicyType='string',    # 注意
    AdjustmentType='string',
    MinAdjustmentStep=123,
    MinAdjustmentMagnitude=123,
    ScalingAdjustment=123,
    Cooldown=123,      # 注意
    MetricAggregationType='string',
    StepAdjustments=[
        {
            'MetricIntervalLowerBound': 123.0,
            'MetricIntervalUpperBound': 123.0,
            'ScalingAdjustment': 123
        },
    ],
    EstimatedInstanceWarmup=123    # 注意
)

参考链接
这里对以下几个值做下解释:

PolicyType (string) -- The policy type. Valid values are SimpleScaling and StepScaling . If the policy type is null, the value is treated as SimpleScaling .

Cooldown (integer) --
The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. If this parameter is not specified, the default cooldown period for the group applies.
This parameter is not supported unless the policy type is SimpleScaling .
For more information, see Understanding Auto Scaling Cooldowns in the Auto Scaling Developer Guide .

EstimatedInstanceWarmup (integer) --
The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. The default is to use the value specified for the default cooldown period for the group.
This parameter is not supported if the policy type is SimpleScaling .
参考链接

从上述文档可以发现boto3已经支持了这两种扩展策略,并且增加了PolicyType属性来对着两种扩展策略进行了区分。

由于在我们的业务应用中,对扩展策略的需求不是很苛刻,因此简单扩展策略就可以满足我们的需求。因此,此处并未对我本次更新造成任何影响。谨以此文记录使用aws和ansible的疑惑之处。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,064评论 5 466
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,606评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,011评论 0 328
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,550评论 1 269
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,465评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,919评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,428评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,075评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,208评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,185评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,191评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,914评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,482评论 3 302
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,585评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,825评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,194评论 2 344
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,703评论 2 339

推荐阅读更多精彩内容

  • 到下月,他离开就一年了。 其实到现在都没想好,是不是要写一写。但不知道要把哪些写下,也不确定是否有了足够沉淀的心境...
    临雪阅读 559评论 0 50
  • 牙难受了几天,疼痛是最俗的病变,身体,心理。其实不管在什么病痛面前,都没有人与当事人感同身受,当事人隐忍或者爆发的...
    莫莫莫姑娘阅读 220评论 0 0
  • 哈尔滨太子乐乳业有限公司用心经营,生产的太子乐奶粉月月抽检合格。太子乐奶粉以卓越的品质和口感,赢得中国千万妈...
    威尔皮特阅读 172评论 0 0
  • 面临老人总是想留住青春的尾巴,好好再过一阵子。原则上讲,人老了是好事,是走向成熟,走向睿智,走向完满的标志。 试想...
    丙由甲桂花儿阅读 232评论 7 3