我需要将挂起的进程添加到 Cloudformation。
我尝试添加 SuspendedProcesses
属性。
ASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
DesiredCapacity: 1
MinSize: 1
MaxSize: 2
LaunchConfigurationName: !Ref LaunchConfigurationName
SuspendedProcesses:
- ReplaceUnhealthy
但是,我收到一条错误消息,指出它是不受支持的属性。
最佳答案
您可以创建一个 Lambda 函数来修改使用 CustomResource 创建的 ASG。这还需要一个 IAM::Role,因为 Lambda 函数需要对 IAM::Role 的引用作为其定义的一部分。
记入https://gist.github.com/atward/9573b9fbd3bfd6c453158c28356bec05对于大部分内容:
ASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
DesiredCapacity: 1
MinSize: 1
MaxSize: 2
LaunchConfigurationName: !Ref LaunchConfigurationName
AsgProcessModificationRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Policies:
- PolicyName: AsgProcessModification
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- autoscaling:ResumeProcesses
- autoscaling:SuspendProcesses
Resource: "*"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
AsgProcessModifierFunction:
Type: AWS::Lambda::Function
Properties:
Description: Modifies ASG processes during CF stack creation
Code:
ZipFile: |
import cfnresponse
import boto3
def handler(event, context):
props = event['ResourceProperties']
client = boto3.client('autoscaling')
try:
response = client.suspend_processes(AutoScalingGroupName=props['AutoScalingGroupName'], 'ReplaceUnhealthy'])
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
except Exception as e:
cfnresponse.send(event, context, cfnresponse.FAILED, {})
Handler: index.handler
Role:
Fn::GetAtt:
- AsgProcessModificationRole
- Arn
Runtime: python2.7
ModifyAsg:
Type: AWS::CloudFormation::CustomResource
Version: 1
Properties:
ServiceToken:
Fn::GetAtt:
- AsgProcessModifierFunction
- Arn
AutoScalingGroupName:
Ref: ASG
ScalingProcesses:
- ReplaceUnhealthy
关于aws-cloudformation - 使用 Cloudformation 将挂起的进程添加到自动缩放组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54204110/