Last active
May 15, 2020 13:42
-
-
Save shentonfreude/56ff4aa6a9b3e6d014a52de22cc299e2 to your computer and use it in GitHub Desktop.
Send the CONTINUE lifecycle hook so the ASG knows our EC2 came up successfully. This allows ASG launches to continue successfully if the UserData is unsuccessful.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
# Send the CONTINUE lifecycle hook so the ASG knows our EC2 came up successfully. | |
# If the CONTINUE fails, don't care, assume it already was continued | |
REGION="us-east-1" | |
INSTANCE_ID=$1 | |
if [ -z $INSTANCE_ID ] ; then echo Specify INSTANCE_ID ; exit 1; fi | |
ASG_NAME=`aws --output text --region $REGION autoscaling describe-auto-scaling-instances --query 'AutoScalingInstances[?InstanceId==\`'$INSTANCE_ID'\`].AutoScalingGroupName|[0]'` | |
if [ -z $ASG_NAME ] ; then echo Could not get ASG_NAME ; exit 1; fi | |
LIFECYCLE_HOOK_NAME=`aws --region $REGION autoscaling describe-lifecycle-hooks --auto-scaling-group-name ${ASG_NAME} --query 'LifecycleHooks[].LifecycleHookName' --output text` | |
if [ -z $LIFECYCLE_HOOK_NAME ] ; then echo Could not get LIFECYCLE_HOOK_NAME ; exit 1; fi | |
echo "# REGION=$REGION INSTANCE_ID=$INSTANCE_ID ASG_NAME=$ASG_NAME LIFECYCLE_HOOK_NAME=$LIFECYCLE_HOOK_NAME" | |
aws autoscaling complete-lifecycle-action --region $REGION --instance-id $INSTANCE_ID --lifecycle-hook-name $LIFECYCLE_HOOK_NAME --auto-scaling-group-name $ASG_NAME --lifecycle-action-result CONTINUE | |
if [ $? -ne 0 ] | |
then | |
echo WARNING Failed to send complete-lifecycle-action CONTINUE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment