cfn-signal: send a success or failure signal for a CloudFormation resource with a CreationPolicy (aws-cfn-bootstrap)
cfn-signal -e EXIT_CODE --stack STACK --resource LOGICAL_ID --region REGION
Options you will use
-e, --exit-code CODE- 0 = SUCCESS, anything else = FAILURE (usually -e $? after the setup command)
-s, --stack NAME- the stack name or ID
-r, --resource ID- the logical ID of the resource with the CreationPolicy (the instance or Auto Scaling group)
--region REGION- the stack's Region
-i, --id ID- a unique ID for this signal (default: the instance ID)
Examples
$ cfn-signal -e $? --stack web --resource WebServer --region eu-central-1from the user data, after the setup (on Amazon Linux: /opt/aws/bin/cfn-signal; on Ubuntu, pip-install aws-cfn-bootstrap first)
$ cfn-signal -e 1 --stack web --resource WebServerreport a failure: the stack rolls back now instead of after the timeout
Gotchas
- Run it at the end of the user data, after the application is up: the resource stays CREATE_IN_PROGRESS until Count signals arrive, or fails after Timeout ("Failed to receive 1 resource signal(s) within the specified duration") and the stack rolls back.
- It needs no credentials: CloudFormation checks that the instance belongs to the stack.
Try cfn-signal in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.