DescribeVpcEndpoints 搭配 使用 CLI - AWS SDK 程式碼範例

文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK GitHub

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeVpcEndpoints 搭配 使用 CLI

下列程式碼範例示範如何使用 DescribeVpcEndpoints

CLI
AWS CLI

描述您的VPC端點

下列describe-vpc-endpoints範例顯示所有VPC端點的詳細資訊。

aws ec2 describe-vpc-endpoints

輸出:

{ "VpcEndpoints": [ { "PolicyDocument": "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"*\",\"Resource\":\"*\"}]}", "VpcId": "vpc-aabb1122", "NetworkInterfaceIds": [], "SubnetIds": [], "PrivateDnsEnabled": true, "State": "available", "ServiceName": "com.amazonaws.us-east-1.dynamodb", "RouteTableIds": [ "rtb-3d560345" ], "Groups": [], "VpcEndpointId": "vpce-032a826a", "VpcEndpointType": "Gateway", "CreationTimestamp": "2017-09-05T20:41:28Z", "DnsEntries": [], "OwnerId": "123456789012" }, { "PolicyDocument": "{\n \"Statement\": [\n {\n \"Action\": \"*\", \n \"Effect\": \"Allow\", \n \"Principal\": \"*\", \n \"Resource\": \"*\"\n }\n ]\n}", "VpcId": "vpc-1a2b3c4d", "NetworkInterfaceIds": [ "eni-2ec2b084", "eni-1b4a65cf" ], "SubnetIds": [ "subnet-d6fcaa8d", "subnet-7b16de0c" ], "PrivateDnsEnabled": false, "State": "available", "ServiceName": "com.amazonaws.us-east-1.elasticloadbalancing", "RouteTableIds": [], "Groups": [ { "GroupName": "default", "GroupId": "sg-54e8bf31" } ], "VpcEndpointId": "vpce-0f89a33420c1931d7", "VpcEndpointType": "Interface", "CreationTimestamp": "2017-09-05T17:55:27.583Z", "DnsEntries": [ { "HostedZoneId": "Z7HUB22UULQXV", "DnsName": "vpce-0f89a33420c1931d7-bluzidnv.elasticloadbalancing.us-east-1.vpce.amazonaws.com" }, { "HostedZoneId": "Z7HUB22UULQXV", "DnsName": "vpce-0f89a33420c1931d7-bluzidnv-us-east-1b.elasticloadbalancing.us-east-1.vpce.amazonaws.com" }, { "HostedZoneId": "Z7HUB22UULQXV", "DnsName": "vpce-0f89a33420c1931d7-bluzidnv-us-east-1a.elasticloadbalancing.us-east-1.vpce.amazonaws.com" } ], "OwnerId": "123456789012" }, { "VpcEndpointId": "vpce-aabbaabbaabbaabba", "VpcEndpointType": "GatewayLoadBalancer", "VpcId": "vpc-111122223333aabbc", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123", "State": "available", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-01010120203030405" ], "CreationTimestamp": "2020-11-11T08:06:03.522Z", "Tags": [], "OwnerId": "123456789012" } ] }

如需詳細資訊,請參閱 Amazon VPC使用者指南 中的VPC端點

PowerShell
適用於 的工具 PowerShell

範例 1:此範例描述 eu-west-1 區域的一或多個VPC端點。然後,它會將輸出引導至下一個命令,選取 VpcEndpointId 屬性,並將陣列 VPC ID 傳回為字串陣列

Get-EC2VpcEndpoint -Region eu-west-1 | Select-Object -ExpandProperty VpcEndpointId

輸出:

vpce-01a2ab3f4f5cc6f7d vpce-01d2b345a6787890b vpce-0012e34d567890e12 vpce-0c123db4567890123

範例 2:此範例說明區域 eu-west-1 的所有 vpc 端點 VpcId,並選取 VpcEndpointId、 ServiceName 和 PrivateDnsEnabled 屬性以表格格式呈現

Get-EC2VpcEndpoint -Region eu-west-1 | Select-Object VpcEndpointId, VpcId, ServiceName, PrivateDnsEnabled | Format-Table -AutoSize

輸出:

VpcEndpointId VpcId ServiceName PrivateDnsEnabled ------------- ----- ----------- ----------------- vpce-02a2ab2f2f2cc2f2d vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ssm True vpce-01d1b111a1114561b vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ec2 True vpce-0011e23d45167e838 vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ec2messages True vpce-0c123db4567890123 vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ssmmessages True

範例 3:此範例會將 VPC Endpoint vpce-01a2ab3f4f5cc6f7d 的政策文件匯出至 json 檔案

Get-EC2VpcEndpoint -Region eu-west-1 -VpcEndpointId vpce-01a2ab3f4f5cc6f7d | Select-Object -expand PolicyDocument | Out-File vpce_policyDocument.json
  • 如需API詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考 DescribeVpcEndpoints中的 。