Skip to content

Instantly share code, notes, and snippets.

@djk29a
Forked from hummus/gist:8592113
Last active February 22, 2017 03:13
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 djk29a/4888b852aea250d2ae836e939a19064f to your computer and use it in GitHub Desktop.
Save djk29a/4888b852aea250d2ae836e939a19064f to your computer and use it in GitHub Desktop.
aws cli + jq example
wget http://stedolan.github.io/jq/download/linux64/jq || sudo apt-get -y --force-yes install jq || sudo yum install -y jq
aws ec2 describe-instances --filters "Name=tag:Name,Values=$NAME" \
"Name=instance-state-name,Values=running" \
| jq -r \
".Reservations[] | .Instances[] | .InstanceId" \
aws ec2 describe-volumes --filters \
"Name=status,Values=available" \
| jq -r ".Volumes[] | .VolumeId" \
aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.LaunchTime > "2015-01-28") | select(.State.Code != 48) | [.LaunchTime, .State.Name, (.Tags[]|select(.Key=="Name")|.Value)]'
# no dotdee
aws ec2 describe-instances | jq --arg yesterday $(python -c "import datetime as d; print (d.datetime.now() - d.timedelta(hours=24)).strftime('%Y-%m-%d')") -r '.Reservations[].Instances[] | select(.LaunchTime > $yesterday) | select(.State.Code != 48) | (.Tags[]//[]|select(.Key=="Name")|.Value) as $name | "Host \($name) \nHostname \(.PrivateIpAddress)"' >> ~/.ssh/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment