Skip to content

Instantly share code, notes, and snippets.

@farmdawgnation
Created January 18, 2016 22:13
Show Gist options
  • Save farmdawgnation/edc9a9e7c95dedb65434 to your computer and use it in GitHub Desktop.
Save farmdawgnation/edc9a9e7c95dedb65434 to your computer and use it in GitHub Desktop.
A little lightweight server management script I wrote
#!/bin/bash
command -v aws >/dev/null 2>&1 || { echo >&2 "I require the AWS cli, but it is not installed."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq, but it is not installed."; exit 1; }
#export AWS_ACCESS_KEY_ID=ACCESS_KEY_HERE_IF_NOT_ALREADY_IN_ENVIRONMENT
#export AWS_SECRET_ACCESS_KEY=SECRET_KEY_HERE_IF_NOT_ALREADY_IN_ENVIRONMENT
#export AWS_DEFAULT_REGION=REGION_HERE_IF_NOT_ALREADY_IN_ENVIRONMENT
INSTANCE_ID=INSTANCE_ID_HERE
COMMAND=none
FILTER=
if [[ $1 == "start" ]]; then
COMMAND=start-instances
FILTER=.StartingInstances[0]?.CurrentState.Name
elif [[ $1 = "stop" ]]; then
COMMAND=stop-instances
FILTER=.StoppingInstances[0]?.CurrentState.Name
elif [[ $1 = "status" ]]; then
COMMAND=describe-instance-status
FILTER=.InstanceStatuses[0]?.InstanceState.Name
else
echo "Unknown command."
exit 1
fi
aws ec2 $COMMAND --instance-ids $INSTANCE_ID | jq $FILTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment