Cloudformation 堆栈未从 EC2 启动模板中的用户数据接收信号

tkw*_*rgs 5 amazon-web-services aws-cloudformation

在我的模板中,我正在配置一个使用EC2 启动模板的ASG

在本UserData节中,我做了一个cfn-init配置实例,效果很好。

但是,当我执行该cfn-signal命令时,该命令成功(退出代码为 0),但 Cloudformation 堆栈从未收到它,并且堆栈创建/更新失败,并显示Failed to receive 1 resource signal(s) for the current batch. Each resource signal timeout is counted as a FAILURE.

当我检查 Cloudtrail 时,我看到API 调用已完成,并用, (但 a of )SignalResource表示正确的堆栈和资源SUCCESSresponseElementsnull

摘自我的 Cloudformation 模板:

Resources:
  MyLaunchTemplate:
      Type: AWS::EC2::LaunchTemplate
      Metadata:
        'AWS::CloudFormation::Init':
          configSets:
            # lots-o-stuff to be done by cfn-init
      Properties:
        LaunchTemplateData:
          # Remove other attributes for brevity
          UserData:
            Fn::Base64:
              !Sub |
                #!/bin/bash -x
                yum update -y
                # gather ENI
                /opt/aws/bin/cfn-init -c install \
                  --stack ${AWS::StackName} \
                  --resource MyLaunchTemplate \
                  --region ${AWS::Region}
                /opt/aws/bin/cfn-signal -e $? \
                  --stack ${AWS::StackName} \
                  --resource MyAsg \
                  --region ${AWS::Region}
                echo $?
        LaunchTemplateName: my-launch-template
  MyAsg:
    Type: AWS::AutoScaling::AutoScalingGroup
      CreationPolicy:
        AutoScalingCreationPolicy:
          MinSuccessfulInstancesPercent: 100
        ResourceSignal:
          Count: 1
          Timeout: PT10M
      UpdatePolicy:
        AutoScalingReplacingUpdate:
          WillReplace: true
      Properties:
        # Remove other attributes for brevity
        LaunchTemplate:
          LaunchTemplateId: !Ref MyLaunchTemplate
          Version: !GetAtt MyLaunchTemplate.LatestVersionNumber
Run Code Online (Sandbox Code Playgroud)

知道我在这里缺少什么吗?

Vij*_*ana 1

Amazon Linux AMI 版本似乎不是最新的,并且cfn-signal实例上未安装脚本。使用aws-cfn-bootstrap包引导 EC2 实例。

添加yum install -y aws-cfn-bootstrapUserData部分。

另一个可能的原因可能是CreationPolicyTimeout属性的值太低。确保该值足够高,以便在脚本向 AWS CloudFormation 资源发送信号之前运行任务。cfn-signal

如果仍然无法解决问题,请查看AWS 故障排除指南来解决此问题。