[英]CloudFormation cfn-init signal success/failure of the userdata script
I wrote a powershell EC2 userdata script. 我编写了一个Powershell EC2用户数据脚本。 I would like to know how to use cfn-init.exe to signal success/failure back to CloudFormation? 我想知道如何使用cfn-init.exe将成功/失败信号发回CloudFormation? Please provide example and syntax as I am new to CloudFormation. 请提供示例和语法,因为我是CloudFormation的新手。
You need to use cfn-signal command for passing the signal to cloudformation. 您需要使用cfn-signal命令将信号传递到cloudformation。 Please check the documentation at http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html 请检查位于http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html的文档
I have added cloudformation snippet which uses cfn-signal for passing the signal. 我添加了使用cfn-signal传递信号的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. 该脚本确保在通知失败返回cloudformation之前,cloudformation在创建实例上最多等待300秒。
{
"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"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.