Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.17 KB | None | 0 0
  1. aws ec2 describe-instances | jq '.Reservations[].Instances[]'
  2.  
  3. {
  4. "Reservations": [
  5. {
  6. "OwnerId": "1234",
  7. "ReservationId": "r-124991k",
  8. "Groups": [],
  9. "Instances": [
  10. {
  11. "Monitoring": {
  12. "State": "disabled"
  13. },
  14. "PublicDnsName": "",
  15. "State": {
  16. "Code": 16,
  17. "Name": "running"
  18. },
  19. "EbsOptimized": false,
  20. "LaunchTime": "2015-07-31T16:48:01.000Z",
  21. "PrivateIpAddress": "11.123.104.123",
  22. "ProductCodes": [],
  23. "VpcId": "vpc-sdfsdf9109",
  24. "StateTransitionReason": "",
  25. "InstanceId": "i-1223421",
  26. "ImageId": "ami-aklasd131",
  27. "PrivateDnsName": "private.dns.name",
  28. "KeyName": "testkey",
  29. "SecurityGroups": [
  30. {
  31. "GroupName": "secur-grou",
  32. "GroupId": "sg-a3d234a"
  33. }
  34. ],
  35. "ClientToken": "",
  36. "SubnetId": "subnet-57absfsdf",
  37. "InstanceType": "m3.large",
  38. "NetworkInterfaces": [
  39. {
  40. "Status": "in-use",
  41. "MacAddress": "12:c3:f2:5c:5f:4d",
  42. "SourceDestCheck": false,
  43. "VpcId": "vpc-sdfsdf9109",
  44. "Description": "",
  45. "NetworkInterfaceId": "eni-81b1234",
  46. "PrivateIpAddresses": [
  47. {
  48. "Primary": true,
  49. "PrivateIpAddress": "11.123.104.123"
  50. }
  51. ],
  52. "Attachment": {
  53. "Status": "attached",
  54. "DeviceIndex": 0,
  55. "DeleteOnTermination": true,
  56. "AttachmentId": "eni-attach-5asdf234",
  57. "AttachTime": "2015-07-30T16:10:39.000Z"
  58. },
  59. "Groups": [
  60. {
  61. "GroupName": "secur-grou",
  62. "GroupId": "sg-a3d234a"
  63. }
  64. ],
  65. "SubnetId": "subnet-57absfsdf",
  66. "OwnerId": "1234",
  67. "PrivateIpAddress": "11.123.104.123"
  68. }
  69. ],
  70. "SourceDestCheck": false,
  71. "Placement": {
  72. "Tenancy": "default",
  73. "GroupName": "",
  74. "AvailabilityZone": "us-east-1c"
  75. },
  76. "Hypervisor": "xen",
  77. "BlockDeviceMappings": [
  78. {
  79. "DeviceName": "/dev/sda1",
  80. "Ebs": {
  81. "Status": "attached",
  82. "DeleteOnTermination": true,
  83. "VolumeId": "vol-28c882",
  84. "AttachTime": "2015-07-30T16:10:43.000Z"
  85. }
  86. },
  87. {
  88. "DeviceName": "/dev/sdb",
  89. "Ebs": {
  90. "Status": "attached",
  91. "DeleteOnTermination": true,
  92. "VolumeId": "vol-3f1d5",
  93. "AttachTime": "2015-07-30T16:10:43.000Z"
  94. }
  95. },
  96. {
  97. "DeviceName": "/dev/sdg",
  98. "Ebs": {
  99. "Status": "attached",
  100. "DeleteOnTermination": true,
  101. "VolumeId": "vol-81c8b",
  102. "AttachTime": "2015-07-30T16:10:43.000Z"
  103. }
  104. }
  105. ],
  106. "Architecture": "x86_64",
  107. "RootDeviceType": "ebs",
  108. "RootDeviceName": "/dev/sda1",
  109. "VirtualizationType": "hvm",
  110. "Tags": [
  111. {
  112. "Value": "apple",
  113. "Key": "Name"
  114. },
  115. {
  116. "Value": "tag",
  117. "Key": "extra"
  118. }
  119. ],
  120. "AmiLaunchIndex": 0
  121. }
  122. ]
  123. },
  124. {
  125. "OwnerId": "1234",
  126. "ReservationId": "r-2a72342",
  127. "Groups": [],
  128. "Instances": [
  129. {
  130. "Monitoring": {
  131. "State": "disabled"
  132. },
  133. "PublicDnsName": "",
  134. "State": {
  135. "Code": 16,
  136. "Name": "running"
  137. },
  138. "EbsOptimized": false,
  139. "LaunchTime": "2015-07-31T16:48:01.000Z",
  140. "PrivateIpAddress": "11.123.104.83",
  141. "ProductCodes": [],
  142. "VpcId": "vpc-sdfsdf9109",
  143. "StateTransitionReason": "",
  144. "InstanceId": "i-f9271451",
  145. "ImageId": "ami-aklasd131",
  146. "PrivateDnsName": "private.name.here",
  147. "KeyName": "testkey",
  148. "SecurityGroups": [
  149. {
  150. "GroupName": "secur-grou",
  151. "GroupId": "sg-a3d234a"
  152. }
  153. ],
  154. "ClientToken": "",
  155. "SubnetId": "subnet-5llqjwdf",
  156. "InstanceType": "m3.large",
  157. "NetworkInterfaces": [
  158. {
  159. "Status": "in-use",
  160. "MacAddress": "12:ea:06:8b:ff:86",
  161. "SourceDestCheck": false,
  162. "VpcId": "vpc-sdfsdf9109",
  163. "Description": "",
  164. "NetworkInterfaceId": "eni-82kjs91",
  165. "PrivateIpAddresses": [
  166. {
  167. "Primary": true,
  168. "PrivateIpAddress": "11.123.104.13"
  169. }
  170. ],
  171. "Attachment": {
  172. "Status": "attached",
  173. "DeviceIndex": 0,
  174. "DeleteOnTermination": true,
  175. "AttachmentId": "eni-attach-35312341",
  176. "AttachTime": "2015-07-30T17:29:00.000Z"
  177. },
  178. "Groups": [
  179. {
  180. "GroupName": "secur-grou",
  181. "GroupId": "sg-a3d234a"
  182. }
  183. ],
  184. "SubnetId": "subnet-57absfsdf",
  185. "OwnerId": "1234",
  186. "PrivateIpAddress": "11.123.104.83"
  187. }
  188. ],
  189. "SourceDestCheck": false,
  190. "Placement": {
  191. "Tenancy": "default",
  192. "GroupName": "",
  193. "AvailabilityZone": "us-east-1c"
  194. },
  195. "Hypervisor": "xen",
  196. "BlockDeviceMappings": [
  197. {
  198. "DeviceName": "/dev/sda1",
  199. "Ebs": {
  200. "Status": "attached",
  201. "DeleteOnTermination": true,
  202. "VolumeId": "vol-ee1c21",
  203. "AttachTime": "2015-07-30T17:29:02.000Z"
  204. }
  205. },
  206. {
  207. "DeviceName": "/dev/sdb",
  208. "Ebs": {
  209. "Status": "attached",
  210. "DeleteOnTermination": true,
  211. "VolumeId": "vol-13awer",
  212. "AttachTime": "2015-07-30T17:29:02.000Z"
  213. }
  214. },
  215. {
  216. "DeviceName": "/dev/sdg",
  217. "Ebs": {
  218. "Status": "attached",
  219. "DeleteOnTermination": true,
  220. "VolumeId": "vol-3111",
  221. "AttachTime": "2015-07-30T17:29:02.000Z"
  222. }
  223. }
  224. ],
  225. "Architecture": "x86_64",
  226. "RootDeviceType": "ebs",
  227. "RootDeviceName": "/dev/sda1",
  228. "VirtualizationType": "hvm",
  229. "Tags": [
  230. {
  231. "Value": "banana",
  232. "Key": "Name"
  233. },
  234. {
  235. "Value": "tag",
  236. "Key": "extra"
  237. }
  238. ],
  239. "AmiLaunchIndex": 0
  240. }
  241. ]
  242. }
  243. ]
  244. }
  245.  
  246. jq '.Reservations[]|=sort_by(.Instances[].Tags[.Key="Name"].Value)'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement