Created
March 31, 2016 02:47
-
-
Save murarisumit/5f04d2a59b6d04536f39d2957cfc2e61 to your computer and use it in GitHub Desktop.
Stop instance and wait till it's in stopped state.
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 | |
profile=your_creds_profile | |
output=your_output_fomat['text' or 'json' ...] | |
instance_id=i-454645644744 #yourinstance_id here | |
cmd='aws ec2 describe-instances --instance-ids $instance_id --profile $profile' | |
aws ec2 stop-instances --instance-ids $instance_id --profile zeus | |
COUNTER=0 | |
while [ $COUNTER -lt 60 ]; do | |
result=`$cmd | python -c "import json,sys;obj=json.load(sys.stdin);print(obj['Reservations'][0]['Instances'][0]['State']['Name'])"` | |
echo $result | |
if [ "$result" = "stopped" ]; | |
then | |
echo "Instance is now in stopped state" | |
break | |
sleep 10 | |
fi | |
(( COUNTER++ )) | |
echo $COUNTER | |
done | |
#Handling for case if instance takes greater than 10 * 60 secs...till required |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment