Skip to content

Instantly share code, notes, and snippets.

@lox
Created July 1, 2014 07:05
Show Gist options
  • Save lox/b3433a09b2956e929742 to your computer and use it in GitHub Desktop.
Save lox/b3433a09b2956e929742 to your computer and use it in GitHub Desktop.
A bash script to signal CloudFormation WaitConditions without cfn-bootstrap
#!/bin/bash
set -e
## Signal CloudFormation WaitConditions without cfn-bootstrap
## See https://github.com/blake-education/aws-cfn-bootstrap/blob/master/bin/cfn-signal
if [ $# -eq 0 ] ; then
echo "usage: $0 <cfn url> <last exit code>"
exit 1
fi
id=$(hostname -f)"_"$(date +"%s%N")
url="$1"
exitcode="${2:-0}"
# json params
status="SUCCESS"
reason="Configuration Complete"
id="llamas"
data="Application has completed configuration."
# check for failure
if [ "$exitcode" -ne 0 ] ; then
status="FAILURE"
data="Failed with exit code $exitcode"
fi
echo "notifying $url with $status (from $id)"
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-waitcondition.html
curl $url -X PUT -H 'Content-Type:' -d @- <<- JSON
{
"Status" : "$status",
"Reason" : "$reason",
"UniqueId" : "$id",
"Data" : "$data"
}
JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment