与 AWS SDK或CreateVpcEndpoint一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或CreateVpcEndpoint一起使用 CLI

以下代码示例演示如何使用 CreateVpcEndpoint

CLI
AWS CLI

示例 1:创建网关终端节点

以下create-vpc-endpoint示例us-east-1在该区域VPCvpc-1a2b3c4d和 Amazon S3 之间创建网关VPC终端节点,并将路由表rtb-11aa22bb与该终端节点关联起来。

aws ec2 create-vpc-endpoint \ --vpc-id vpc-1a2b3c4d \ --service-name com.amazonaws.us-east-1.s3 \ --route-table-ids rtb-11aa22bb

输出:

{ "VpcEndpoint": { "PolicyDocument": "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":\"\*\",\"Action\":\"\*\",\"Resource\":\"\*\"}]}", "VpcId": "vpc-1a2b3c4d", "State": "available", "ServiceName": "com.amazonaws.us-east-1.s3", "RouteTableIds": [ "rtb-11aa22bb" ], "VpcEndpointId": "vpc-1a2b3c4d", "CreationTimestamp": "2015-05-15T09:40:50Z" } }

有关更多信息,请参阅AWS PrivateLink 指南中的创建网关终端节点

示例 2:创建接口终端节点

以下create-vpc-endpoint示例us-east-1在该区域VPCvpc-1a2b3c4d和 Amazon S3 之间创建了一个接口VPC终端节点。该命令在子网中创建终端节点subnet-1a2b3c4d,将其与安全组关联sg-1a2b3c4d,并添加密钥为 “服务”、值为 “S3” 的标签。

aws ec2 create-vpc-endpoint \ --vpc-id vpc-1a2b3c4d \ --vpc-endpoint-type Interface \ --service-name com.amazonaws.us-east-1.s3 \ --subnet-ids subnet-7b16de0c \ --security-group-id sg-1a2b3c4d \ --tag-specifications ResourceType=vpc-endpoint,Tags=[{Key=service,Value=S3}]

输出:

{ "VpcEndpoint": { "VpcEndpointId": "vpce-1a2b3c4d5e6f1a2b3", "VpcEndpointType": "Interface", "VpcId": "vpc-1a2b3c4d", "ServiceName": "com.amazonaws.us-east-1.s3", "State": "pending", "RouteTableIds": [], "SubnetIds": [ "subnet-1a2b3c4d" ], "Groups": [ { "GroupId": "sg-1a2b3c4d", "GroupName": "default" } ], "PrivateDnsEnabled": false, "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-0b16f0581c8ac6877" ], "DnsEntries": [ { "DnsName": "*.vpce-1a2b3c4d5e6f1a2b3-9hnenorg.s3.us-east-1.vpce.amazonaws.com", "HostedZoneId": "Z7HUB22UULQXV" }, { "DnsName": "*.vpce-1a2b3c4d5e6f1a2b3-9hnenorg-us-east-1c.s3.us-east-1.vpce.amazonaws.com", "HostedZoneId": "Z7HUB22UULQXV" } ], "CreationTimestamp": "2021-03-05T14:46:16.030000+00:00", "Tags": [ { "Key": "service", "Value": "S3" } ], "OwnerId": "123456789012" } }

有关更多信息,请参阅《用户指南》中的创建接口端点 AWS PrivateLink。

示例 3:创建 Gateway Load Balancer 终端节点

以下create-vpc-endpoint示例在VPCvpc-111122223333aabbc和和和与使用网关负载均衡器配置的服务之间创建一个 Gateway Load Balancer 端点。

aws ec2 create-vpc-endpoint \ --service-name com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123 \ --vpc-endpoint-type GatewayLoadBalancer \ --vpc-id vpc-111122223333aabbc \ --subnet-ids subnet-0011aabbcc2233445

输出:

{ "VpcEndpoint": { "VpcEndpointId": "vpce-aabbaabbaabbaabba", "VpcEndpointType": "GatewayLoadBalancer", "VpcId": "vpc-111122223333aabbc", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123", "State": "pending", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-01010120203030405" ], "CreationTimestamp": "2020-11-11T08:06:03.522Z", "OwnerId": "123456789012" } }

有关更多信息,请参阅《用户指南》中的 Gateway Load Balancer 终端节点 AWS PrivateLink。

PHP
SDK for PHP
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

/** * @param string $serviceName * @param string $vpcId * @param array $routeTableIds * @return array */ public function createVpcEndpoint(string $serviceName, string $vpcId, array $routeTableIds): array { try { $result = $this->ec2Client->createVpcEndpoint([ 'ServiceName' => $serviceName, 'VpcId' => $vpcId, 'RouteTableIds' => $routeTableIds, ]); return $result["VpcEndpoint"]; } catch(Ec2Exception $caught){ echo "There was a problem creating the VPC Endpoint: {$caught->getAwsErrorMessage()}\n"; throw $caught; } }
  • 有关API详细信息,请参阅 “AWS SDK for PHP API参考 CreateVpcEndpoint” 中的。

PowerShell
用于 PowerShell

示例 1:此示例在 vpc-0fc1ff23fc23f45b678eb 中为服务 com.amazonaws.eu-west-1.s3 创建了一个新的VPC终端节点 VPC

New-EC2VpcEndpoint -ServiceName com.amazonaws.eu-west-1.s3 -VpcId vpc-0fc1ff23f45b678eb

输出:

ClientToken VpcEndpoint ----------- ----------- Amazon.EC2.Model.VpcEndpoint
  • 有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考CreateVpcEndpoint中的。