gpt4 book ai didi

amazon-web-services - 如何列出属于某个 VPC 的所有资源?

转载 作者:行者123 更新时间:2023-12-04 12:20:44 24 4
gpt4 key购买 nike

在我的 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=<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]'
    原始输出示例(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"
    }
    ]

  • 现在过滤:
  • 第一次--query
     [
    "us-east-1d",
    "57039816848",
    "i-0fe495a6c17bd0f82",
    [
    "44.196.57.169"
    ]
    ]
  • 而对于第二个 --query (另一个 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 控制台
    您可以使用 AWS 控制台执行相同操作。
    在 EC2->网络接口(interface)下,搜索所需的 vpc-id在搜索栏中。
    enter image description here

    关于amazon-web-services - 如何列出属于某个 VPC 的所有资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61997608/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com