-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathasg-lifecycle-hook
More file actions
31 lines (25 loc) · 2.02 KB
/
asg-lifecycle-hook
File metadata and controls
31 lines (25 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null`
REGION=`curl -s http://169.254.169.254/latest/dynamic/instance-identity/document 2>/dev/null | jq -r .region`
# Find the Auto Scaling Group name from the Elastic Beanstalk environment
ASG=`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" \
--region $REGION --output json | jq -r '.[][] | select(.Key=="aws:autoscaling:groupName") | .Value'`
LCS=`aws autoscaling describe-auto-scaling-instances --region $REGION --instance-ids $INSTANCE_ID | jq .AutoScalingInstances[].LifecycleState`
if [ $LCS == '"Pending:Wait"' ]
then
RESULT=`aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --region $REGION --lifecycle-hook-name $ASG \
--auto-scaling-group-name $ASG --instance-id $INSTANCE_ID`
fi
====================================
INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null`
REGION=`curl -s http://169.254.169.254/latest/dynamic/instance-identity/document 2>/dev/null | jq -r .region`
# Find the Auto Scaling Group name from the Elastic Beanstalk environment
ASG=`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" \
--region $REGION --output json | jq -r '.[][] | select(.Key=="aws:autoscaling:groupName") | .Value'`
HOOK_NAME=`aws --region $REGION autoscaling describe-lifecycle-hooks --auto-scaling-group-name $ASG | jq -r '.[][].LifecycleHookName'`
LCS=`aws autoscaling describe-auto-scaling-instances --region $REGION --instance-ids $INSTANCE_ID | jq .AutoScalingInstances[].LifecycleState`
if [ $LCS == '"Pending:Wait"' ]
then
RESULT=`aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --region $REGION --lifecycle-hook-name $HOOK_NAME \
--auto-scaling-group-name $ASG --instance-id $INSTANCE_ID`
fi