Skip to content

Instantly share code, notes, and snippets.

@gannino
Forked from endofcake/userdata.sh
Created March 12, 2019 10:24
Show Gist options
  • Save gannino/63ccd3f4c8c56d2d940c836570fb65ae to your computer and use it in GitHub Desktop.
Save gannino/63ccd3f4c8c56d2d940c836570fb65ae to your computer and use it in GitHub Desktop.
Check that ecs-agent is running and signal back to CloudFormation
#!/bin/bash
set -euo pipefail
<...>
echo "Checking that agent is running"
until $(curl --output /dev/null --silent --head --fail http://localhost:51678/v1/metadata); do
printf '.'
sleep 1
done
exit_code=$?
printf "\nDone\n"
# Can't signal back if the stack is in UPDATE_COMPLETE state, so ignore failures to do so.
# CFN will roll back if it expects the signal but doesn't get it anyway.
echo "Reporting $exit_code exit code to Cloudformation"
/opt/aws/bin/cfn-signal \
--exit-code "$exit_code" \
--stack "$CFN_STACK" \
--resource ASG \
--region "$REGION" || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment