【问题标题】:CloudFormation cfn-init signal success/failure of the userdata scriptCloudFormation cfn-init 信号 userdata 脚本的成功/失败
【发布时间】:2016-09-19 06:39:27
【问题描述】:

我编写了一个 powershell EC2 用户数据脚本。我想知道如何使用 cfn-init.exe 向 CloudFormation 发送成功/失败信号?请提供示例和语法,因为我是 CloudFormation 的新手。

【问题讨论】:

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


    【解决方案1】:

    您需要使用 cfn-signal 命令将信号传递给 cloudformation。 请查看http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html的文档

    我添加了 cloudformation sn-p,它使用 cfn-signal 传递信号。

    脚本确保 cloudformation 在实例上等待最多 300 秒才能创建,然后再向 cloudformation 发出失败信号。

    {
      "AWSTemplateFormatVersion": "2010-09-09",
      "Resources": {
        "EC2Instance": {
          "Type": "AWS::EC2::Instance",
          "Properties": {
            "ImageId": "<AMI>",
            "InstanceType": "<Instance Type>",
            "KeyName": "<Key_pair>",
            "Monitoring": "false",
            "UserData": {
              "Fn::Base64": {
                "Fn::Join": [
                  "",
                  [
                    "#!/bin/bash -e\n",
                    "yum update -y aws-cfn-bootstrap\n",
                    "/opt/aws/bin/cfn-signal -e 0 -r \"Failed to create Instance\" ",
                    {
                      "Ref": "WaitHandle"
                    },
                    "'\n"
                  ]
                ]
              }
            }
          }
        },
        "WaitHandle": {
          "Type": "AWS::CloudFormation::WaitConditionHandle"
        },
        "WaitCondition": {
          "Type": "AWS::CloudFormation::WaitCondition",
          "DependsOn": "EC2Instance",
          "Properties": {
            "Handle": {
              "Ref": "WaitHandle"
            },
            "Timeout": "300"
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 2019-06-27
      • 2016-05-07
      • 2019-07-08
      相关资源
      最近更新 更多