我在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启动新实例。有关如何使更新策略有效的任何想法吗?
由于
答案 0 :(得分:1)
更改LaunchConfiguration元数据不会触发AutoScaling UpdatePolicy。您需要更改LaunchConfiguration属性以触发UpdatePolicy。最简单的方法是对UserData进行简单的更改。