【发布时间】:2021-09-19 21:14:00
【问题描述】:
如何在 aws cli 表输出上应用类似 sql 的查询。 我的 aws cli 命令如下:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].{ImageId: ImageId, InstanceId: InstanceId, InstanceType: InstanceType,State: State.Name, KeyName : KeyName,AZ: Placement.AvailabilityZone,Tenancy: Placement.Tenancy,LaunchTime: LaunchTime, PrivateIpAddress: PrivateIpAddress, PublicIpAddress: PublicIpAddress, VpcId: VpcId, SubnetId: SubnetId, Architecture: Architecture,SG: SecurityGroups[0].GroupName,SG_ID: SecurityGroups[0].GroupId,OwnerID: NetworkInterfaces[0].OwnerId}' --region us-east-1 --output table
我想对上面的 aws cli 查询表输出做如下操作:
我想按实例类型对所有 InstanceId 进行分组,如下所示:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| DescribeInstances |
+------------+---------------+------------------------+----------------------+---------------+-------------+---------------------------+---------------+-------------------+------------------+--------------------------------------------------------------------------------------------------------+-----------------------+-------------+------------------+----------+----------------+
| AZ | Architecture | ImageId | InstanceId | InstanceType | KeyName | LaunchTime | OwnerID | PrivateIpAddress | PublicIpAddress | SG | SG_ID | State | SubnetId | Tenancy | VpcId |
+------------+---------------+------------------------+----------------------+---------------+-------------+---------------------------+---------------+-------------------+------------------+--------------------------------------------------------------------------------------------------------+-----------------------+-------------+------------------+----------+----------------+
| us-east-1b| x86_64 | ami-1ecae776 | i-dad4180f | t2.micro | TruCentric | 2015-09-08T15:27:59.000Z | 401331319872 | 10.51.1.232 | None | build-vpc-BastionSecurityGroup-1RRONL28DLJAM | sg-6d476b0a | stopped | subnet-1d323d6a | default | vpc-4976b12d |
| us-east-1a| x86_64 | ami-1ecae776 | i-e8c2614b | | TruCentric | 2015-09-08T15:27:59.000Z | 401331319872 | 10.51.0.209 | None | build-vpc-BastionSecurityGroup-1RRONL28DLJAM | sg-6d476b0a | stopped | subnet-b8a3f793 | default | vpc-4976b12d |
| us-east-1a| x86_64 | ami-d05e75b8 | i-d4cc6f77 | | acquia_ops | 2019-07-15T15:34:59.000Z | 401331319872 | 10.51.0.220 | 52.91.20.69 | build-vpc-ApplicationSecurityGroup-81J8RJLV25JH | sg-6e476b09 | running | subnet-b8a3f793 | default | vpc-4976b12d |
| us-east-1a| x86_64 | ami-d05e75b8 | i-3c43ef9f | | acquia_ops | 2016-04-23T23:13:14.000Z | 401331319872 | 10.52.0.85 | 54.165.202.171 | dev-vpn-SecurityGroup-U7UONIX6LIB9 | sg-67f9d100 | running | subnet-48124563 | default | vpc-21d71145 |
【问题讨论】:
-
我打算建议您考虑使用lebinh/aq,它允许您使用 SQL 查询 AWS 资源,但似乎 broken at present 尽管您可能能够使其与某些 Python 包版本一起使用管理调整。
-
抱歉,您的问题不清楚。 “按实例类型对所有 InstanceId 进行分组”是什么意思?
标签: amazon-web-services amazon-ec2 aws-cli