Last active
October 2, 2018 20:07
-
-
Save nmagee/d13a67b82859fcef53acff568ecb114d to your computer and use it in GitHub Desktop.
Use JQ to parse AWS CLI requests
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 | |
# Display the EIPs associated with all of your instances: | |
aws ec2 describe-instances \ | |
| jq -r .Reservations[].Instances[].PublicIpAddress | |
# Display the EIP attached to a specific EC2 instance: | |
aws ec2 describe-instances --instance-ids i-1a2b3c4d5e6f7g8h9i \ | |
| jq -r .Reservations[0].Instances[0].PublicIpAddress | |
# Retrieve all tags associated with an instance: | |
aws ec2 describe-instances --instance-ids i-1a2b3c4d5e6f7g8h9i \ | |
| jq -r .Reservations[0].Instances[0].Tags | |
# List all EC2 instances attached to an ELB: | |
aws elb describe-load-balancers \ | |
| jq -r .LoadBalancerDescriptions[0].Instances[0].InstanceId | |
# Put a value into a variable for logic. This request tells you | |
# the state of an instance [stopped|running] | |
state=`aws ec2 describe-instances --instance-ids i-02438e5e535b738a0 \ | |
| jq -r .Reservations[0].Instances[0].State.Name` | |
echo $state | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment