#やりたいこと
下記aws cliの結果をjqを使用して、整形したいと考えています。
・aws ec2 describe-instances
json
1{ 2 "Reservations": [ 3 { 4 "Instances": [ 5 { 6 "Monitoring": { 7 "State": "disabled" 8 }, 9 "PublicDnsName": "", 10 "State": { 11 "Code": 16, 12 "Name": "running" 13 }, 14 "EbsOptimized": false, 15 "LaunchTime": "2019-10-29T13:04:12.000Z", 16 "PublicIpAddress": "52.198.68.107", 17 "PrivateIpAddress": "192.168.0.239", 18 "ProductCodes": [], 19 "VpcId": "vpc-0b749cd08a045897f", 20 "CpuOptions": { 21 "CoreCount": 1, 22 "ThreadsPerCore": 1 23 }, 24 "StateTransitionReason": "", 25 "InstanceId": "i-0a8b3eb95ade9e6a3", 26 "EnaSupport": true, 27 "ImageId": "ami-0ab3e16f9c414dee7", 28 "PrivateDnsName": "ip-192-168-0-239.ap-northeast-1.compute.internal", 29 "KeyName": "20190706", 30 "SecurityGroups": [ 31 { 32 "GroupName": "default", 33 "GroupId": "sg-08649cd4d367766a5" 34 } 35 ], 36 "ClientToken": "", 37 "SubnetId": "subnet-0266ed89ed664b6ed", 38 "InstanceType": "t2.micro", 39 "CapacityReservationSpecification": { 40 "CapacityReservationPreference": "open" 41 }, 42 "NetworkInterfaces": [ 43 { 44 "Status": "in-use", 45 "MacAddress": "06:8a:fb:cf:a0:74", 46 "SourceDestCheck": true, 47 "VpcId": "vpc-0b749cd08a045897f", 48 "Description": "Primary network interface", 49 "NetworkInterfaceId": "eni-0a33ecdc5664da995", 50 "PrivateIpAddresses": [ 51 { 52 "PrivateIpAddress": "192.168.0.239", 53 "Primary": true, 54 "Association": { 55 "PublicIp": "52.198.68.107", 56 "PublicDnsName": "", 57 "IpOwnerId": "amazon" 58 } 59 } 60 ], 61 "SubnetId": "subnet-0266ed89ed664b6ed", 62 "Attachment": { 63 "Status": "attached", 64 "DeviceIndex": 0, 65 "DeleteOnTermination": true, 66 "AttachmentId": "eni-attach-07e7814c4e4ae2860", 67 "AttachTime": "2019-10-29T13:04:12.000Z" 68 }, 69 "Groups": [ 70 { 71 "GroupName": "default", 72 "GroupId": "sg-08649cd4d367766a5" 73 } 74 ], 75 "Ipv6Addresses": [], 76 "OwnerId": "273384484291", 77 "PrivateIpAddress": "192.168.0.239", 78 "Association": { 79 "PublicIp": "52.198.68.107", 80 "PublicDnsName": "", 81 "IpOwnerId": "amazon" 82 } 83 } 84 ], 85 "SourceDestCheck": true, 86 "Placement": { 87 "Tenancy": "default", 88 "GroupName": "", 89 "AvailabilityZone": "ap-northeast-1a" 90 }, 91 "Hypervisor": "xen", 92 "BlockDeviceMappings": [ 93 { 94 "DeviceName": "/dev/xvda", 95 "Ebs": { 96 "Status": "attached", 97 "DeleteOnTermination": true, 98 "VolumeId": "vol-01fb9be55736cd3ae", 99 "AttachTime": "2019-10-29T13:04:13.000Z" 100 } 101 } 102 ], 103 "Architecture": "x86_64", 104 "RootDeviceType": "ebs", 105 "IamInstanceProfile": { 106 "Id": "AIPAT7JX4FXBYMT4GVBB7", 107 "Arn": "arn:aws:iam::273384484291:instance-profile/fullaccess" 108 }, 109 "RootDeviceName": "/dev/xvda", 110 "VirtualizationType": "hvm", 111 "Tags": [ 112 { 113 "Value": "cpc", 114 "Key": "SID" 115 }, 116 { 117 "Value": "20191029", 118 "Key": "Date" 119 }, 120 { 121 "Value": "tst1", 122 "Key": "Name" 123 } 124 ], 125 "HibernationOptions": { 126 "Configured": false 127 }, 128 "AmiLaunchIndex": 0 129 } 130 ], 131 "ReservationId": "r-000d20fcca6bb70d9", 132 "Groups": [], 133 "OwnerId": "273384484291" 134 } 135 ] 136}
#整形結果
jqコマンドを使用して下記出力行いたいと考えています。
52.198.68.107 20191029 tst1
↑PublicIpAddressと、TagsのKeyがDateのValueと、TagsのKeyがNameのValue。
Reservations[].Instances[].PublicIpAddressでPublicAddressは出力できますが、
TagsがxxのValueを表示するという横並びの方法に悩んでおります。
selectで頑張ってみてはいますが、上手くいきません。
jqマスター助けてください。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。