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

标签 amazon-web-services aws-cloudformation

在我的模板中,我正在配置一个使用 EC2 Launch template 的 ASG。

UserData部分,我做了一个cfn-init配置实例,效果很好。

但是当我执行 cfn-signal 时命令,该命令成功(退出代码为 0),但 Cloudformation 堆栈从未收到它,并且堆栈创建/更新失败,并显示 无法接收当前批处理的 1 个资源信号。每个资源信号超时都算作一次失败。

当我检查 Cloudtrail 时,我看到 SignalResource API 调用已完成,并使用 SUCCESS 发出正确的堆栈和资源信号(但是 responseElementsnull)

摘 self 的 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 Linux AMI 版本似乎不是最新的,并且实例上未安装 cfn-signal 脚本。使用 aws-cfn-bootstrap 引导 EC2 实例包裹。

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

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

如果仍然不起作用,请查看 AWS Troubleshooting Guide对于这个问题。

关于amazon-web-services - Cloudformation 堆栈未从 EC2 启动模板中的用户数据接收信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58925187/

相关文章:

ios - 无法在 xcode 8 beta 6 上编译 AWS CustomIdentityProvider

bash - 如何在启动数据库时从 cloudformation 模板创建 RDS 架构?

amazon-web-services - 使用 AWS SES 事件处理自定义子域

amazon-web-services - (AWS) CloudFormation 堆栈与 Amazon Linux 2

amazon-web-services - 如何自动化 aws 托管 UI 的 Logo

amazon-web-services - 云信息 : Import existing resource

amazon-s3 - 使用亚马逊的云服务器/应用程序/工具进行编程的经验和技巧?

amazon-web-services - AWS cloudformation Spot实例参数

node.js - AWS DynamoDb 中的哈希键和范围键到底意味着什么?

amazon-web-services - 在第 431 行第 15 列解析 block 映射时未找到预期的键