如何列出属于某个 VPC 的所有资源? [英] How can I list all resources that belongs to a certain VPC?
问题描述
在我的 AWS 账户中,我的 VPC 很少.我正在尝试找到一种方法来列出位于某个 VPC 下的所有资源.
谢谢!!
您可以通过两种方式实现:AWS CLI 或 AWS 控制台.
AWS CLI
您可以使用 AWS CLI 列出与 VPC 关联的所有 ENI,并使用 --query
参数美化输出以获取包含所需字段(AZ、实例 ID 等)的资源列表.).
`aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=
--query 'NetworkInterfaces[*].[AvailabilityZone, OwnerId, Attachment.InstanceId, PrivateIpAddresses[*].Association.PublicIp]' `aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=
--query 'NetworkInterfaces[*].[RequesterId,Description]' 原始输出示例(VPC 上只有一个实例):
网络接口":[{协会":{IpOwnerId":亚马逊",PublicDnsName":ec2-54-196-57-169.compute-1.amazonaws.com",公共IP":54.196.57.169"},附件":{附加时间":2020-08-24T10:59:16+00:00",附件 ID":eni-attach-047e562690aabbffd",DeleteOnTermination":真,设备索引":0,InstanceId":i-0fe495a6c17bd0f82",InstanceOwnerId":570398916848",状态":已附加"},可用性区域":us-east-1d",说明":",组":[{GroupName":launch-wizard-1",GroupId":sg-0aa7d8257bb487e1b"}],接口类型":接口",IPv6 地址":[],MacAddress":0e:58:38:33:9a:31",NetworkInterfaceId":eni-0b20855178d276783",所有者 ID":570398916848",PrivateDnsName":ip-172-31-34-30.ec2.internal",PrivateIpAddress":172.31.34.30",私有IP地址":[{协会":{IpOwnerId":亚马逊",PublicDnsName":ec2-54-196-57-169.compute-1.amazonaws.com",公共IP":54.196.57.169"},主要":真,PrivateDnsName":ip-172-31-34-30.ec2.internal",私有IP地址":172.31.34.30"}],请求者管理":假,SourceDestCheck":真,状态":使用中",SubnetId":subnet-e2bc5fbd",标签集":[],VpcId":vpc-6ad2e110"}]
现在过滤了:
对于第一个
<预><代码> [us-east-1d",57039816848",i-0fe495a6c17bd0f82",[44.196.57.169"]]--query
对于第二个
<预><代码> [亚马逊弹性",ElastiCache alon-001"],[亚马逊弹性",ElastiCache alon-002"],[975289786086",arn:aws:ecs:us-east-2:57039916848:attachment/22a90802-fae7-4afb-9a7e-43e6f4be8ca4"],[074689309192",NAT 网关接口 nat-069344579d8bda20"],[亚马逊易北",ELB app/EC2Co-EcsEl-YX74WCWEGOK/0b6d7bc60b540b1"],[亚马逊易北",ELB app/EC2Co-EcsEl-YX74WCWGGOK/0b6bd7c60b540b1"],[亚马逊弹性",ElastiCache alon-003"]--query
(另一个 VPC):
AWS 控制台
您可以使用 AWS 控制台执行相同操作.在 EC2-> 网络接口下,在搜索栏中搜索所需的 vpc-id
.
At my AWS account, I have few VPC. I'm trying to find a way to list all resources that located under a certain VPC.
Thanks!!
You can do it in two ways: AWS CLI or AWS console.
AWS CLI
You can use AWS CLI to list all ENIs associated with the VPC and prettify the output using the --query
parameter to get a resource list with the desired fields (AZ, instance-id, etc.).
-
`aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=<vpc-id> --query 'NetworkInterfaces[*].[AvailabilityZone, OwnerId, Attachment.InstanceId, PrivateIpAddresses[*].Association.PublicIp]'
-
`aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=<vpc-id> --query 'NetworkInterfaces[*].[RequesterId,Description]'
A sample of the raw output (only one instance on the VPC):
"NetworkInterfaces": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-54-196-57-169.compute-1.amazonaws.com", "PublicIp": "54.196.57.169" }, "Attachment": { "AttachTime": "2020-08-24T10:59:16+00:00", "AttachmentId": "eni-attach-047e562690aabbffd", "DeleteOnTermination": true, "DeviceIndex": 0, "InstanceId": "i-0fe495a6c17bd0f82", "InstanceOwnerId": "570398916848", "Status": "attached" }, "AvailabilityZone": "us-east-1d", "Description": "", "Groups": [ { "GroupName": "launch-wizard-1", "GroupId": "sg-0aa7d8257bb487e1b" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "0e:58:38:33:9a:31", "NetworkInterfaceId": "eni-0b20855178d276783", "OwnerId": "570398916848", "PrivateDnsName": "ip-172-31-34-30.ec2.internal", "PrivateIpAddress": "172.31.34.30", "PrivateIpAddresses": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-54-196-57-169.compute-1.amazonaws.com", "PublicIp": "54.196.57.169" }, "Primary": true, "PrivateDnsName": "ip-172-31-34-30.ec2.internal", "PrivateIpAddress": "172.31.34.30" } ], "RequesterManaged": false, "SourceDestCheck": true, "Status": "in-use", "SubnetId": "subnet-e2bc5fbd", "TagSet": [], "VpcId": "vpc-6ad2e110" } ]
And now filtered:
For the first
--query
[ "us-east-1d", "57039816848", "i-0fe495a6c17bd0f82", [ "44.196.57.169" ] ]
And for the second
--query
(another VPC):[ "amazon-elasticache", "ElastiCache alon-001" ], [ "amazon-elasticache", "ElastiCache alon-002" ], [ "975289786086", "arn:aws:ecs:us-east-2:57039916848:attachment/22a90802-fae7-4afb-9a7e-43e6f4be8ca4" ], [ "074689309192", "Interface for NAT Gateway nat-069344579d8bda20" ], [ "amazon-elb", "ELB app/EC2Co-EcsEl-YX74WCWEGOK/0b6d7bc60b540b1" ], [ "amazon-elb", "ELB app/EC2Co-EcsEl-YX74WCWGGOK/0b6bd7c60b540b1" ], [ "amazon-elasticache", "ElastiCache alon-003" ]
AWS Console
You can do the same using the AWS console.
Under EC2->Network Interfaces, search for the desired vpc-id
in the search bar.
这篇关于如何列出属于某个 VPC 的所有资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!