| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
You can use the cfn-signal helper script to pause the stack creation process. Use the cfn-signal script in conjunction with two AWS CloudFormation resources:
For more information about how to use wait conditions in your template, see Creating Wait Conditions in a Template.
cfn-signal --success|-ssignal.to.send\ --reason|-rresource.status.reason\ --data|-ddata\ --id|-iunique.id\ --exit-code|-eexit.code\waitconditionhandle.url
| Name | Description | Required |
|---|---|---|
|
|
if true, signal SUCCESS, else FAILURE. Type: Boolean Default: |
No |
|
|
A status reason for the resource event (currently only used on failure) - defaults to 'Configuration failed' if success is false. Type: String. | No |
|
|
Data to send back with the waitConditionHandle. Defaults to blank. Type: String. Default: blank |
No |
|
|
The unique id to send back with the WaitConditionHandle. Type: String. Default: The machine's Fully Qualified Domain Name (FQDN). |
No |
|
|
The error code from a process that can be used to determine success or failure. If
specified, the Type: String. Examples: |
No |
|
|
A pre-signed URL that you can use to signal success or failure to an associated WaitCondition Type: String. |
Yes |
Example 1
A common usage pattern is to use cfn-init and cfn-signal together. The cfn-signal call uses the return status of the call to cfn-init (using the $? shell construct). If the application fails to install, the WaitCondition will fail to create and the stack will rollback.
"MyInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
:
},
"Properties": {
"ImageId" : "ami-12345678",
"UserData" : {
"Fn::Base64" : {
"Fn::Join" : ["", [
"#!/bin/bash\n",
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
" -r MyInstance ",
" --region ", { "Ref" : "AWS::Region" },
"\n",
"/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "MyHandle" }, "'\n",
] ]
}
}
}
},Example 2
The following snippet shows another common usage pattern in which a function calls cfn-signal. Wrapping cfn-signal in a function makes it easier to call cfn-signal from multiple places.
"# Helper function\n",
"function error_exit\n",
"{\n",
" /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
" exit 1\n",
"}\n",The following snippet shows the error_exit function called in two commands.
"# Setup MySQL, create a user and a database\n",
"mysqladmin -u root password '", { "Ref" : "DBRootPassword" },
"' || error_exit 'Failed to initialize root password'\n",
"mysql -u root --password='", { "Ref" : "DBRootPassword" },
"' < /tmp/setup.mysql || error_exit 'Failed to initialize database'\n",Examples in Sample Templates
Several AWS CloudFormation sample templates use cfn-signal, including the following templates.