Created
May 27, 2015 07:15
-
-
Save okisanjp/9578f18ff850fd257db7 to your computer and use it in GitHub Desktop.
aws-cliの標準出力をjqで整形 ref: http://qiita.com/okisanjp/items/52bbcd7bb751f7ab5174
This file contains hidden or 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
| $ aws ec2 describe-instances | |
| { | |
| "Reservations": [ | |
| { | |
| "OwnerId": "xxxxxxxxxxx", | |
| "ReservationId": "r-xxxxxxx", | |
| "Groups": [], | |
| "Instances": [ | |
| { | |
| "Monitoring": { | |
| "State": "disabled" | |
| }, | |
| "PublicDnsName": "", | |
| "State": { | |
| "Code": 16, | |
| "Name": "running" | |
| }, | |
| ・ | |
| ・ | |
| ・ | |
| "Architecture": "x86_64", | |
| "RootDeviceType": "ebs", | |
| "RootDeviceName": "/dev/xvda", | |
| "VirtualizationType": "hvm", | |
| "Tags": [ | |
| { | |
| "Value": "example.com", | |
| "Key": "Name" | |
| } | |
| ], | |
| "AmiLaunchIndex": 0 | |
| } | |
| ] | |
| } | |
| ] | |
| } |
This file contains hidden or 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
| $ brew install jq | |
| ==> Downloading https://homebrew.bintray.com/bottles/jq-1.4.yosemite.bottle.tar.gz | |
| ######################################################################## 100.0% | |
| ==> Pouring jq-1.4.yosemite.bottle.tar.gz |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq '.Reservations[].Instances[].Tags[]' | |
| { | |
| "Value": "app.example.com", | |
| "Key": "Name" | |
| } | |
| { | |
| "Value": "db.example.com", | |
| "Key": "Name" | |
| } | |
| { | |
| "Value": "elasticsearch.example.com", | |
| "Key": "Name" | |
| } | |
| { | |
| "Value": "example.com", | |
| "Key": "Name" | |
| } |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq '.Reservations[].Instances[].Tags[].Value' | |
| "app.example.com" | |
| "db.example.com" | |
| "elasticsearch.example.com" | |
| "example.com" |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | .PrivateIpAddress + "\t" + .Tags[].Value' | |
| 192.168.1.125 app.example.com | |
| 192.168.1.14 db.example.com | |
| 192.168.1.250 elasticsearch.example.com | |
| 192.168.1.230 example.com |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq '.Reservations[].Instances[].NetworkInterfaces[].Groups[]' | |
| "GroupName": "web server", | |
| "GroupId": "sg-d5e80ow8" | |
| } | |
| { | |
| "GroupName": "WordPress powered by AMIMOTO -HVM--Version- 1-1-AutogenByAWSMP-1", | |
| "GroupId": "sg-7dc54320" | |
| } | |
| { | |
| "GroupName": "streamdata", | |
| "GroupId": "sg-d5es4rd3" | |
| } | |
| { | |
| "GroupName": "db", | |
| "GroupId": "sg-d5e8fd83y" | |
| } |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq -c '.Reservations[].Instances[].NetworkInterfaces[].Groups[]' | |
| {"GroupName":"web server","GroupId":"sg-d5e80ow8"} | |
| {"GroupName":"WordPress powered by AMIMOTO -HVM--Version- 1-1-AutogenByAWSMP-1","GroupId":"sg-7dc54320"} | |
| {"GroupName":"streamdata","GroupId":"sg-d5es4rd3"} | |
| {"GroupName":"db","GroupId":"sg-d5e8fd83y"} |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq -M '.Reservations[].Instances[].NetworkInterfaces[].Groups[]' | |
| "GroupName": "web server", | |
| "GroupId": "sg-d5e80ow8" | |
| } | |
| { | |
| "GroupName": "WordPress powered by AMIMOTO -HVM--Version- 1-1-AutogenByAWSMP-1", | |
| "GroupId": "sg-7dc54320" | |
| } | |
| { | |
| "GroupName": "streamdata", | |
| "GroupId": "sg-d5es4rd3" | |
| } | |
| { | |
| "GroupName": "db", | |
| "GroupId": "sg-d5e8fd83y" | |
| } |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq '.Reservations[].Instances[].NetworkInterfaces[].Groups[] | select(.GroupName == "web server")' | |
| { | |
| "GroupName": "web server", | |
| "GroupId": "sg-d5e80ow8" | |
| } |
This file contains hidden or 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
| $ aws ec2 describe-instances | jq -r -c '.Reservations[].Instances[] | select(.NetworkInterfaces[].Groups[].GroupName == "web server") | .PrivateIpAddress + "\t" + .Tags[].Value' | |
| 192.168.1.230 example.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment