2

I have an AWS CLI script that will take AMI of instance, create a launch configuration, update the autoscaling group with latest launch config and perform instance refresh operation.

I don't want to perform instance refresh operation unless the AMI is in "available state". So, I am thinking of adding a condition that checks every 10 seconds.

Here is my exisiting script file:

...
#Create AMI
IMAGE=`aws ec2 create-image --instance-id ${INST_ID} --name NEW-IMAGE-${TIME} --no-reboot --output text`
echo "Create Image of instance ${INST_ID}"

#Create new launch Configuration
aws autoscaling create-launch-configuration --launch-configuration-name ${NEW_LC} --image-id ${IMAGE} --instance-type t2.micro --key forclient --associate-public-ip-address --security-groups sg-01be135cb14a00960
echo "Create new Launch Configuration ${NEW_LC}"

#Update Auto Scaling Group to use new Launch Configuration
aws autoscaling update-auto-scaling-group --auto-scaling-group-name ${ASG_NAME} --launch-configuration-name ${NEW_LC}
echo "New Launch Configuration is updated in ASG ${NEW_LC}"

aws autoscaling start-instance-refresh --auto-scaling-group-name ${ASG_NAME}

I don't want to run the 'start-instance-refresh' command until the 'create-image' is in 'available' state.

What changes do I need to make on this script file for this to happen?

1 Answer 1

2

You can use image-available waiter after you create the image:

aws ec2 wait image-available --image-ids ${IMAGE}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.