Last active
June 24, 2020 15:11
-
-
Save csrwng/645bf7f0586dbc33b74c422e94b84e5b to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -e | |
CLUSTER_ID="${CLUSTER_ID:-}" | |
if [[ -z "${CLUSTER_ID}" ]]; then | |
CLUSTER_ID="$(cat ~/data/install/current/metadata.json | jq -r '.aws.identifier[] | select(keys[]|contains("kubernetes.io")) | keys[0]')" | |
fi | |
echo "CLUSTER_ID=${CLUSTER_ID}" | |
echo "Instances for current cluster" | |
aws ec2 describe-instances --filters "Name=tag-key,Values=${CLUSTER_ID}" | \ | |
jq -r '.Reservations[].Instances[] | "\(.InstanceId) \(.State.Name) \(.Tags[] | select(.Key == "Name") | .Value)"' | sort -k2 | |
INSTANCES="$(aws ec2 describe-instances --filters "Name=tag-key,Values=${CLUSTER_ID}" | \ | |
jq -r '.Reservations[].Instances[].InstanceId' | tr '\n' ' ')" | |
echo "Starting instances..." | |
aws ec2 start-instances --instance-ids ${INSTANCES} > /dev/null |
This file contains 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 | |
set -e | |
CLUSTER_ID="${CLUSTER_ID:-}" | |
if [[ -z "${CLUSTER_ID}" ]]; then | |
CLUSTER_ID="$(cat ~/data/install/current/metadata.json | jq -r '.aws.identifier[] | select(keys[]|contains("kubernetes.io")) | keys[0]')" | |
fi | |
echo "CLUSTER_ID=${CLUSTER_ID}" | |
echo "Instances for current cluster" | |
aws ec2 describe-instances --filters "Name=tag-key,Values=${CLUSTER_ID}" | \ | |
jq -r '.Reservations[].Instances[] | "\(.InstanceId) \(.State.Name) \(.Tags[] | select(.Key == "Name") | .Value)"' | grep -i "running" | sort -k2 | |
INSTANCES="$(aws ec2 describe-instances --filters "Name=tag-key,Values=${CLUSTER_ID}" | \ | |
jq -r '.Reservations[].Instances[] | "\(.InstanceId) \(.State.Name)"' | grep -i "running" | awk '{ print $1}' | tr '\n' ' ')" | |
echo "Stopping instances..." | |
aws ec2 stop-instances --instance-ids ${INSTANCES} > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment