From bffb753b1b64966f4c300933d975313597e71691 Mon Sep 17 00:00:00 2001 From: joshrosso Date: Thu, 17 Nov 2016 08:32:35 -0800 Subject: [PATCH] cleanup ec2: Ignore terminated instances If users had previously terminated an instance and recreated it, e.g manually in the console, the clean-up script will have issues since terminated instance remain available in AWS some time. This commit only takes instances with a state of stopped or running for termination. --- docs/10-cleanup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/10-cleanup.md b/docs/10-cleanup.md index 452b58a..72967b7 100644 --- a/docs/10-cleanup.md +++ b/docs/10-cleanup.md @@ -67,7 +67,7 @@ KUBERNETES_HOSTS=(controller0 controller1 controller2 worker0 worker1 worker2) ``` for host in ${KUBERNETES_HOSTS[*]}; do INSTANCE_ID=$(aws ec2 describe-instances \ - --filters "Name=tag:Name,Values=${host}" | \ + --filters "Name=tag:Name,Values=${host}" "Name=instance-state-name,Values=running,stopped" | \ jq -j '.Reservations[].Instances[].InstanceId') aws ec2 terminate-instances --instance-ids ${INSTANCE_ID} done