AutoScalingGroup 中的 UpdatePolicy 无法更新实例

AutoScalingGroup 中的 UpdatePolicy 无法更新实例

我在 CloudFormation 中使用以下设置来创建自动扩展组:

"myautoscalinggroup": {
  "Type": "AWS::AutoScaling::AutoScalingGroup",
  "UpdatePolicy" : {
    "AutoScalingRollingUpdate" : {
     "MinInstancesInService" : "1",
     "MaxBatchSize" : "2",
     "WaitOnResourceSignals" : "true",
     "PauseTime" : "PT5M"
    }
  },
  "Properties": {
    "AvailabilityZones": [
      "ap-southeast-2b",
      "ap-southeast-2a"
    ],
    "Cooldown": "300",
    "DesiredCapacity": { "Ref" : "InstanceCount"},
    "HealthCheckGracePeriod": "300",
    "HealthCheckType": "EC2",
    "MaxSize": "5",
    "MinSize": "1",
    "VPCZoneIdentifier": { "Ref" : "WebServerSubnets" },
    "LaunchConfigurationName": {
      "Ref": "mylaunchconfiguration"
    },
    "LoadBalancerNames": [
      {
        "Ref": "myloadbalancer"
      }
    ],
    "TerminationPolicies": [
      "Default"
    ]
  }
},
"mylaunchconfiguration": {
  "Type": "AWS::AutoScaling::LaunchConfiguration",
  "Metadata" : {
    "Comment": "Get web page",
    "AWS::CloudFormation::Init" : {
      "config" : {
        "packages" : {
          "yum" : {
            "httpd" : []
          }
        },
        "sources" : { 
          "/var/www/html" :  "address to web-site contents"
        },
        "services" : {
          "sysvinit" : {
            "httpd"    : { "enabled" : "true", "ensureRunning" : "true" }
          }
        }
      }
    }
  },
  "Properties": {
    "ImageId": "ami-fd9cecc7",
    "InstanceType": "t2.micro",
    "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash -xe\n",
      "yum update -y aws-cfn-bootstrap\n",
      "/opt/aws/bin/cfn-init -v ",
         "         --stack ", { "Ref" : "AWS::StackName" },
         "         --resource mylaunchconfiguration ",
         "         --region ", { "Ref" : "AWS::Region" }, "\n",

      "/opt/aws/bin/cfn-signal -e $? ",
         "         --stack ", { "Ref" : "AWS::StackName" },
         "         --resource myautoscalinggroup ",
         "         --region ", { "Ref" : "AWS::Region" }, "\n"

    ]]}},
    "KeyName": "myKey",
    "SecurityGroups": [{ "Ref" : "mySecurityGroup" }],
    "BlockDeviceMappings": [
      {
        "DeviceName": "/dev/xvda",
        "Ebs": {
          "VolumeSize": 8
        }
      }
    ]
  }
}

但是,当我使用新的启动配置更新堆栈时,更新策略无法更新实例。但是,当我手动终止实例时,AutoScalingGroup 会启动并使用更新的 LaunchConfiguration 启动新实例。关于如何使更新策略发挥作用,您有什么想法吗?

谢谢

相关内容