Skip to content

Instantly share code, notes, and snippets.

@seventhskye
Last active July 23, 2016 05:37
Show Gist options
  • Save seventhskye/9a99c5e0cb623b9d1cc77fe6758fed68 to your computer and use it in GitHub Desktop.
Save seventhskye/9a99c5e0cb623b9d1cc77fe6758fed68 to your computer and use it in GitHub Desktop.
A script to collect InstanceIds from AWS by a tag: ScheduledUptime in this case. The list can then be used for other tasks such as shutting down instances.
#!/bin/bash
# The TAG_KEY and TAG_VALUE environment variables
# can be set before running the script otherwise the
# default are used.
IDS`aws ec2 describe-instances \
--filter "Name=tag:${TAG_KEY:-ScheduledUptime},Values=${TAG_VALUE:-True}" \
--query 'Reservations[*].Instances[*].[InstanceId]' \
--output text`
aws ec2 start-instances --instance-ids $IDS --output text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment