Created
December 16, 2016 18:37
-
-
Save ReedD/78d1b114f0a52785043299eba1356a9d to your computer and use it in GitHub Desktop.
Signal an AWS Auto Scaling Group that an instance has come into service within an ELB.
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 | |
# Dependencies | |
# - awscli | |
# - jq | |
# Needed IAM permissions | |
# - elasticloadbalancing:DescribeInstanceHealth | |
# - elasticloadbalancing:DescribeLoadBalancers | |
# - autoscaling:DescribeAutoScalingGroups | |
STACK_NAME="STACK NAME" | |
INSTANCE_ID=$(curl -s http://instance-data/latest/meta-data/instance-id) | |
REGION=$(curl -s http://instance-data/latest/dynamic/instance-identity/document | jq .region -r) | |
ELB_NAME=$(aws elb describe-load-balancers --region us-east-1 | jq -r ".LoadBalancerDescriptions[] | select(.Instances[].InstanceId == \"${INSTANCE_ID}\") | .LoadBalancerName") | |
ASG_NAME=$(aws autoscaling describe-auto-scaling-groups --region us-east-1 | jq -r ".AutoScalingGroups[] | select(.Instances[].InstanceId == \"${INSTANCE_ID}\") | .AutoScalingGroupName") | |
while sleep 1; do | |
STATE=$(aws elb describe-instance-health --region ${REGION} --load-balancer-name ${ELB_NAME} | jq --raw-output ".InstanceStates[] | select(.InstanceId == \"${INSTANCE_ID}\") | .State") | |
if [ $STATE == "InService" ] | |
then | |
break | |
fi | |
done | |
/opt/aws/bin/cfn-signal \ | |
--success true \ | |
--stack ${STACK_NAME} \ | |
--resource ${ASG_NAME} \ | |
--region ${REGION} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment