Last active
November 23, 2016 13:52
-
-
Save alexstaravoitau/17c8639d8a4225268f64d5c1b59a4a50 to your computer and use it in GitHub Desktop.
Stops your AWS instance. Check out my post about usage of this script: http://navoshta.com/aws-tensorflow/
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 | |
# Checks current AWS instance state and stops it if it's running. | |
AWS_INSTANCE_ID="<Your instance ID here>" | |
AWS_STATE=$(aws ec2 describe-instances --instance-ids $AWS_INSTANCE_ID --query "Reservations[*].Instances[*].State.Name" --output text) | |
if [ "$AWS_STATE" == "running" ]; then | |
aws ec2 stop-instances --instance-ids $AWS_INSTANCE_ID >/dev/null | |
echo -n "The AWS instance is now stopping. It usually takes a while, so feel free to CTRL+C if you don't want to wait till the instance has fully stopped." | |
echo "Stopping instance" | |
# Wait till the instance has actually stopped. | |
while AWS_STATE=$(aws ec2 describe-instances --instance-ids $AWS_INSTANCE_ID --query "Reservations[*].Instances[*].State.Name" --output text); test "$AWS_STATE" != "stopped"; do | |
sleep 5; echo -n '.' | |
done | |
echo " AWS instance stopped. " | |
else | |
echo "AWS instance is not running." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment