Skip to content

Instantly share code, notes, and snippets.

@franklanganke
Created May 19, 2015 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franklanganke/f00db2aa016ee21c76cf to your computer and use it in GitHub Desktop.
Save franklanganke/f00db2aa016ee21c76cf to your computer and use it in GitHub Desktop.
Stop EC2 instances by tag
#!/bin/bash
# 19.05.2015 Frank Langanke
# stop ec2 instances by tag "off-time" with value "true", can be used as cronjob
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
_instances=$(aws ec2 describe-instances --filters "Name=tag:off-time,Values=true" --query Reservations[].Instances[].[InstanceId] --output text)
aws ec2 stop-instances --instance-ids $_instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment