CloudFormation cfn-init 信号用户数据脚本的成功/失败 [英] CloudFormation cfn-init signal success/failure of the userdata script

查看:33
本文介绍了CloudFormation cfn-init 信号用户数据脚本的成功/失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wrote a powershell EC2 userdata script. I would like to know how to use cfn-init.exe to signal success/failure back to CloudFormation? Please provide example and syntax as I am new to CloudFormation.

推荐答案

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

You need to use cfn-signal command for passing the signal to cloudformation. Please check the documentation at http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html

我添加了使用 cfn-signal 传递信号的 cloudformation 片段.

I have added cloudformation snippet which uses cfn-signal for passing the signal.

脚本确保 cloudformation 在实例创建前最多等待 300 秒,然后再向 cloudformation 发出故障信号.

The scripting ensures, that cloudformation waits a maximum of 300 seconds on the instance to get created, before signaling a failure back to 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"
      }
    }
  }
}

这篇关于CloudFormation cfn-init 信号用户数据脚本的成功/失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆