cfn-signal UPDATE_ROLLBACK_COMPLETE状态且无法发出信号

时间:2018-03-02 16:03:23

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

有时,命令cfn-signal正在崩溃:

  

ValidationError:Stack   ARN:AWS:cloudformation:EU-西-1:XXXXX:堆/ XXX / XXXXX   处于UPDATE_ROLLBACK_COMPLETE状态且无法发出信号

使用此命令:

/usr/local/bin/cfn-signal -e 0 \ 
  --stack arn:aws:cloudformation:eu-west-1:XXX:stack/XXX/XXXX \
  --resource AutoScalingGroup \
  --region eu-west-1

我不明白为什么CloudFormation状态是相关的?我相信正在等待生命周期事件的AutoScalingGroup?

当我手动完成实例生命周期时,没有问题:

aws autoscaling complete-lifecycle-action \
  --auto-scaling-group-name XXXX \
  --lifecycle-hook-name CodeDeploy-managed-automatic-launch-deployment-hook-XX \
  --instance-id i-XX \
  --lifecycle-action-result CONTINUE \
  --region eu-west-1

UserData脚本的一部分:

 UserData:
    Fn::Base64: !Sub |
      [...]
      # Setup CodeDeploy
      sudo /home/ubuntu/install-codedeploy-agent auto
      rm /home/ubuntu/install-codedeploy-agent

      # Install the files and packages from the metadata
      /usr/local/bin/cfn-init -v \
        --stack ${AWS::StackId} \
        --resource LaunchConfiguration \
        --region ${AWS::Region}

      # All done so signal success to CloudFormation
      /usr/local/bin/cfn-signal -e $? \
        --stack ${AWS::StackId} \
        --resource AutoScalingGroup \
        --region ${AWS::Region}

      # Start CodeDeploy agent
      sudo service codedeploy-agent start
      sudo service codedeploy-agent status

AutoScaling组定义:

AutoScalingGroup:
  Type: AWS::AutoScaling::AutoScalingGroup
  Properties:
    AvailabilityZones:
      Fn::GetAZs: !Ref AWS::Region
    LaunchConfigurationName: !Ref LaunchConfiguration
    MinSize: 1
    MaxSize: 2
    DesiredCapacity: 1
    TargetGroupARNs:
      - !Ref ElasticLoadBalancerTargetGroup
    HealthCheckType: ELB
    HealthCheckGracePeriod: 600 # in seconds
  CreationPolicy:
    ResourceSignal:
      Count: 1
      Timeout: PT15M # 15 minutes
  UpdatePolicy:
    AutoScalingRollingUpdate:
      PauseTime: PT15M # 15 minutes
      WaitOnResourceSignals: true

1 个答案:

答案 0 :(得分:1)

据我所知cfn-signal与自动缩放生命周期钩子完全无关。

其目的是向CloudFormation发出信号,表明给定的自动缩放组中的实例已准备就绪。当CloudFormation收到确定数量的成功信号时,它会认为ASG为CREATE_COMPLETEUPDATE_COMPLETE。如果由于模板中的某些其他问题导致应该接收信号的堆栈已回退,cfn-signal将失败,因为其信号不再与_COMPLETE状态的堆栈相关。