【问题标题】:AWS Cloudformation: Suspend process in Auto Scaling GroupAWS Cloudformation:暂停 Auto Scaling 组中的进程
【发布时间】:2019-12-20 12:17:53
【问题描述】:

在 Cloudformation 中定义 Auto Scaling 组资源时,我需要将 AZRebalance 添加为 SuspendProcesses 的一部分。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-rollingupdate 文档指出,这是 AutoScalingRollingUpdate UpdatePolicy 的一部分。

"UpdatePolicy" : {
  "AutoScalingRollingUpdate" : {
    "MaxBatchSize" : Integer,
    "MinInstancesInService" : Integer,
    "MinSuccessfulInstancesPercent" : Integer,
    "PauseTime" : String,
    "SuspendProcesses" : [ List of processes ],
    "WaitOnResourceSignals" : Boolean
  }
}

不幸的是,这会导致 ASG 中的实例在 LaunchConfig 发生更改时重新启动。在创建堆栈时有什么方法可以两全其美?即

1) 在创建堆栈时暂停 ASG 中的一些进程
2) 在 LaunchConfig 更改时禁用 ASG 中实例的滚动重启

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation autoscaling


    【解决方案1】:

    我认为您不能使用云形成来暂停 Auto Scaling 组中的进程,但忽略启动配置更改。

    一种选择是直接调用自动缩放来暂停进程,而不是通过云形成

    【讨论】:

      【解决方案2】:

      目前,CloudFormation AutoScaling Group 资源没有任何启用挂起进程的属性。

      此外,使用 UpdatePolicy 意味着这些选项仅适用于从 CloudFormation 更新而不是创建期间的 ASG。

      一种解决方法是查看自定义资源来实现这一点:

      https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

      此外,以下链接可能会帮助您了解如何通过示例了解:

      https://gist.github.com/atward/9573b9fbd3bfd6c453158c28356bec05

      下面是一个假设的解决方案(我也没有测试过上面的解决方案):

      #"Create" behavior, will make suspend_processes API call for AZ Rebalancing
                client = boto3.client("autoscaling")
                ASGName = event['ResourceProperties']['ASGname']
                if event['RequestType'] == 'Create':
                    response = client.suspend_processes(
                        AutoScalingGroupName = ASGName,  
                        ScalingProcesses=['AZRebalance']
                    )
                    responseData = {}
                    cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData) #Telling CFN it was a success here
      

      但我建议您改进实现并添加 try catch 块来处理异常并发出失败信号,以便 CloudFormation 堆栈不会挂起(即它将等待来自自定义资源的信号(成功/失败) ) 并正确失败。

      您以类似的方式处理更新行为:

      elif event['RequestType'] == 'Update': ........ 
      

      【讨论】:

        猜你喜欢
        • 2018-07-27
        • 2016-10-29
        • 2018-03-25
        • 2021-12-11
        • 2018-07-11
        • 2016-12-25
        • 2012-12-25
        • 2020-10-05
        • 2017-07-24
        相关资源
        最近更新 更多