【问题标题】:Cloudformation Stack not receiving signal from userdata in EC2 Launch TemplateCloudformation 堆栈未从 EC2 启动模板中的用户数据接收信号
【发布时间】:2020-03-14 10:47:42
【问题描述】:

在我的模板中,我配置了一个使用 EC2 Launch template 的 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 时,我看到 SignalResource API 调用已完成,用 SUCCESS 表示正确的堆栈和资源,(但 responseElementsnull

摘自我的 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

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

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    我最近也遇到了类似的问题。由于某种原因,cfn-signals 似乎不适用于启动模板。出于测试目的,我将启动模板更改为启动配置,cfn 信号工作正常。 AWS 不支持启动模板的原因很奇怪。

    【讨论】:

      【解决方案2】:

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

      UserData 部分添加yum install -y aws-cfn-bootstrap

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

      如果它仍然不起作用,请查看AWS Troubleshooting Guide 以了解此问题。

      【讨论】:

      • Timeout 在 10 分钟内正常(信号在实例启动后 2 分钟内发送,如 /var/log/cloud-init-output.log 所示)。我确认我使用的是最新的 Amazon Linux 2 AMI,并在 Cloudtrail 日志中看到发件人是 "userAgent": "CfnTools/1.4-31 (Linux-4.14.146-120.181.amzn2.x86_64-x86_64-with-glibc2.2.5) python/2.7.16"
      猜你喜欢
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 2020-04-19
      • 2017-05-13
      • 2018-11-24
      • 2017-08-13
      相关资源
      最近更新 更多