翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
AWS SDK または CLI CreateVpcEndpoint
で を使用する
以下のコード例は、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-namecom.amazonaws.us-east-1.s3
\ --route-table-idsrtb-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-typeInterface
\ --service-namecom.amazonaws.us-east-1.s3
\ --subnet-idssubnet-7b16de0c
\ --security-group-idsg-1a2b3c4d
\ --tag-specificationsResourceType=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 ユーザーガイド」の「インターフェイス VPC エンドポイントの作成」を参照してください。
例 3: Gateway Load Balancer エンドポイントを作成するには
次の
create-vpc-endpoint
の例では、VPCvpc-111122223333aabbc
と、Gateway Load Balancer を使用して設定されたサービスの間に Gateway Load Balancer エンドポイントを作成します。aws ec2 create-vpc-endpoint \ --service-name
com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123
\ --vpc-endpoint-typeGatewayLoadBalancer
\ --vpc-idvpc-111122223333aabbc
\ --subnet-idssubnet-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" } }
詳細については、AWS 「 PrivateLink ユーザーガイド」の「Gateway Load Balancer エンドポイント」を参照してください。
-
API の詳細については、「AWS CLI コマンドリファレンス」の「CreateVpcEndpoint
」を参照してください。
-
- 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
-
- Tools for PowerShell
-
例 1: この例では、VPC vpc-0fc1ff23f45b678eb でサービス com.amazonaws.eu-west-1.s3 の新しい VPC エンドポイントを作成します。
New-EC2VpcEndpoint -ServiceName com.amazonaws.eu-west-1.s3 -VpcId vpc-0fc1ff23f45b678eb
出力:
ClientToken VpcEndpoint ----------- ----------- Amazon.EC2.Model.VpcEndpoint
-
API の詳細については、「 コマンドレットリファレンス」のCreateVpcEndpoint」を参照してください。 AWS Tools for PowerShell
-
- Python
-
- SDK for Python (Boto3)
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 class VpcWrapper: """Encapsulates Amazon Elastic Compute Cloud (Amazon EC2) Amazon Virtual Private Cloud actions.""" def __init__(self, ec2_client: boto3.client): """ Initializes the VpcWrapper with an EC2 client. :param ec2_client: A Boto3 Amazon EC2 client. This client provides low-level access to AWS EC2 services. """ self.ec2_client = ec2_client @classmethod def from_client(cls) -> "VpcWrapper": """ Creates a VpcWrapper instance with a default EC2 client. :return: An instance of VpcWrapper initialized with the default EC2 client. """ ec2_client = boto3.client("ec2") return cls(ec2_client) def create_vpc_endpoint( self, vpc_id: str, service_name: str, route_table_ids: list[str] ) -> Dict[str, Any]: """ Creates a new VPC endpoint for the specified service and associates it with the specified route tables. :param vpc_id: The ID of the VPC to create the endpoint in. :param service_name: The name of the service to create the endpoint for. :param route_table_ids: A list of IDs of the route tables to associate with the endpoint. :return: A dictionary representing the newly created VPC endpoint. """ try: response = self.ec2_client.create_vpc_endpoint( VpcId=vpc_id, ServiceName=service_name, RouteTableIds=route_table_ids, ) return response["VpcEndpoint"] except ClientError as err: logger.error( "Couldn't create VPC endpoint for service %s. Here's why: %s: %s", service_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
-
API の詳細については、 AWS SDK for CreateVpcEndpoint」を参照してください。
-
AWS SDK 開発者ガイドとコード例の完全なリストについては、「」を参照してくださいを使用して Amazon EC2リソースを作成する AWS SDK。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。