Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Benutzen CreateVpcEndpoint mit einem AWS SDK oder CLI
Die folgenden Code-Beispiele zeigen, wie CreateVpcEndpoint verwendet wird.
Beispiele für Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Im folgenden Codebeispiel können Sie diese Aktion im Kontext sehen:
- CLI
-
- AWS CLI
-
Beispiel 1: So erstellen Sie einen Gateway-Endpunkt
Im folgenden Beispiel für
create-vpc-endpointwird ein Gateway-VPC-Endpunkt zwischen der VPCvpc-1a2b3c4dund Amazon S3 in der Regionus-west-2erstellt und die Routing-Tabellertb-11aa22bbmit dem Endpunkt verknüpft.aws ec2 create-vpc-endpoint \ --vpc-idvpc-1a2b3c4d\ --service-namecom.amazonaws.us-west-2.s3\ --route-table-idsrtb-11aa22bbAusgabe:
{ "VpcEndpoint": { "PolicyDocument": "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"*\",\"Resource\":\"*\"}]}", "VpcId": "vpc-1a2b3c4d", "State": "available", "ServiceName": "com.amazonaws.us-west-2.s3", "RouteTableIds": [ "rtb-11aa22bb" ], "VpcEndpointId": "vpc-1a2b3c4d", "CreationTimestamp": "2015-05-15T09:40:50Z" } }Weitere Informationen finden Sie unter Erstellen Sie einen Gateway-Endpunkt in der AWS PrivateLink Benutzerleitfaden.
Beispiel 2: So erstellen Sie einen Schnittstellenendpunkt
Im folgenden Beispiel für
create-vpc-endpointwird ein VPC-Schnittstellenendpunkt zwischen der VPCvpc-1a2b3c4dund Amazon S3 in der Regionus-west-2erstellt. Der Befehl erstellt den Endpunkt im Subnetzsubnet-1a2b3c4d, ordnet ihn der Sicherheitsgruppesg-1a2b3c4dzu und fügt ein Tag mit dem Schlüssel „Service“ und dem Wert „S3" hinzu.aws ec2 create-vpc-endpoint \ --vpc-idvpc-1a2b3c4d\ --vpc-endpoint-typeInterface\ --service-namecom.amazonaws.us-west-2.s3\ --subnet-idssubnet-7b16de0c\ --security-group-idssg-1a2b3c4d\ --tag-specificationsResourceType=vpc-endpoint,Tags=[{Key=service,Value=S3}]Ausgabe:
{ "VpcEndpoint": { "VpcEndpointId": "vpce-1a2b3c4d5e6f1a2b3", "VpcEndpointType": "Interface", "VpcId": "vpc-1a2b3c4d", "ServiceName": "com.amazonaws.us-west-2.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-west-2.vpce.amazonaws.com", "HostedZoneId": "Z7HUB22UULQXV" }, { "DnsName": "*.vpce-1a2b3c4d5e6f1a2b3-9hnenorg-us-west-2c.s3.us-west-2.vpce.amazonaws.com", "HostedZoneId": "Z7HUB22UULQXV" } ], "CreationTimestamp": "2021-03-05T14:46:16.030000+00:00", "Tags": [ { "Key": "service", "Value": "S3" } ], "OwnerId": "123456789012" } }Weitere Informationen finden Sie unter Erstellen Sie einen Schnittstellen-VPC-Endpunkt in der AWS PrivateLink Benutzerleitfaden.
Beispiel 3: So erstellen Sie einen Endpunkt für Gateway Load Balancer
Folgendes
create-vpc-endpointBeispiel erstellt einen Gateway Load Balancer-Endpunkt zwischen VPCvpc-1a2b3c4d5e6f7a8b9und einen Dienst, der mit einem Gateway Load Balancer konfiguriert wird.aws ec2 create-vpc-endpoint \ --service-namecom.amazonaws.vpce.us-west-2.vpce-svc-123123a1c43abc123\ --vpc-endpoint-typeGatewayLoadBalancer\ --vpc-idvpc-1a2b3c4d5e6f7a8b9\ --subnet-idssubnet-0011aabbcc2233445Ausgabe:
{ "VpcEndpoint": { "VpcEndpointId": "vpce-aabbaabbaabbaabba", "VpcEndpointType": "GatewayLoadBalancer", "VpcId": "vpc-1a2b3c4d5e6f7a8b9", "ServiceName": "com.amazonaws.vpce.us-west-2.vpce-svc-123123a1c43abc123", "State": "pending", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-01010120203030405" ], "CreationTimestamp": "2020-11-11T08:06:03.522Z", "OwnerId": "123456789012" } }Weitere Informationen finden Sie unter Gateway Load Balancer-Endpunkte in der AWS PrivateLink Benutzerleitfaden.
Beispiel 4: So erstellen Sie einen Ressourcenendpunkt
Im folgenden Beispiel für
create-vpc-endpointwird ein Ressourcenendpunkt erstellt.aws ec2 create-vpc-endpoint \ --vpc-endpoint-typeResource\ --vpc-idvpc-1a2b3c4d5e6f7a8b9\ --subnet-idssubnet-0011aabbcc2233445\ --resource-configuration-arnarn:aws:vpc-lattice-us-east-1:123456789012:resourceconfiguration/rcfg-0123abcde98765432Ausgabe:
{ "VpcEndpoint": { "VpcEndpointId": "vpce-00939a7ed9EXAMPLE", "VpcEndpointType": "Resource", "VpcId": "vpc-1a2b3c4d5e6f7a8b9", "State": "Pending", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "Groups": [ { "GroupId": "sg-03e2f15fbfc09b000", "GroupName": "default" } ], "IpAddressType": "IPV4", "PrivateDnsEnabled": false, "CreationTimestamp": "2025-02-06T23:38:49.525000+00:00", "Tags": [], "OwnerId": "123456789012", "ResourceConfigurationArn": "arn:aws:vpc-lattice:us-west-2:123456789012:resourceconfiguration/rcfg-0123abcde98765432" } }Weitere Informationen finden Sie unter Ressourcen-Endpunkte in der AWS PrivateLink Benutzerleitfaden.
Beispiel 5: So erstellen Sie einen Service-Netzwerkendpunkt
Im folgenden Beispiel für
create-vpc-endpointwird ein Service-Netzwerkendpunkt erstellt.aws ec2 create-vpc-endpoint \ --vpc-endpoint-typeServiceNetwork\ --vpc-idvpc-1a2b3c4d5e6f7a8b9\ --subnet-idssubnet-0011aabbcc2233445\ --service-network-arnarn:aws:vpc-lattice:us-west-2:123456789012:servicenetwork/sn-0101abcd5432abcd0\ --security-group-idssg-0123456789012abcdAusgabe:
{ "VpcEndpoint": { "VpcEndpointId": "vpce-0f00567fa8EXAMPLE", "VpcEndpointType": "ServiceNetwork", "VpcId": "vpc-1a2b3c4d5e6f7a8b9", "State": "Pending", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "Groups": [ { "GroupId": "sg-0123456789012abcd", "GroupName": "my-security-group" } ], "IpAddressType": "IPV4", "PrivateDnsEnabled": false, "CreationTimestamp": "2025-02-06T23:44:20.449000+00:00", "Tags": [], "OwnerId": "123456789012", "ServiceNetworkArn": "arn:aws:vpc-lattice:us-west-2:123456789012:servicenetwork/sn-0101abcd5432abcd0" } }Weitere Informationen finden Sie unter Endpunkte im Servicenetzwerk in der AWS PrivateLink Benutzerleitfaden.
-
Einzelheiten zur API finden Sie unter CreateVpcEndpoint
in AWS CLI Befehlsreferenz.
-
- PHP
-
- SDK für PHP
-
Anmerkung
Es gibt noch mehr GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-
einrichten und ausführen. /** * @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; } }-
Einzelheiten zur API finden Sie unter CreateVpcEndpoint in AWS SDK für PHP API-Referenz.
-
- PowerShell
-
- Werkzeuge für PowerShell V4
-
Beispiel 1: In diesem Beispiel wird ein neuer VPC-Endpunkt für den Service com.amazonaws.eu-west-1.s3 in der VPC vpc-0fc1ff23f45b678eb erstellt
New-EC2VpcEndpoint -ServiceName com.amazonaws.eu-west-1.s3 -VpcId vpc-0fc1ff23f45b678ebAusgabe:
ClientToken VpcEndpoint ----------- ----------- Amazon.EC2.Model.VpcEndpoint-
API-Details finden Sie unter CreateVpcEndpoint in AWS -Tools für PowerShell Cmdlet-Referenz (V4).
-
- Werkzeuge für PowerShell V5
-
Beispiel 1: In diesem Beispiel wird ein neuer VPC-Endpunkt für den Service com.amazonaws.eu-west-1.s3 in der VPC vpc-0fc1ff23f45b678eb erstellt
New-EC2VpcEndpoint -ServiceName com.amazonaws.eu-west-1.s3 -VpcId vpc-0fc1ff23f45b678ebAusgabe:
ClientToken VpcEndpoint ----------- ----------- Amazon.EC2.Model.VpcEndpoint-
API-Details finden Sie unter CreateVpcEndpoint in AWS -Tools für PowerShell Cmdlet-Referenz (V5).
-
- Python
-
- SDK für Python (Boto3)
-
Anmerkung
Es gibt noch mehr GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-
einrichten und ausführen. 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-
Einzelheiten zur API finden Sie unter CreateVpcEndpoint in AWS API-Referenz für das SDK für Python (Boto3).
-
- SAP ABAP
-
- SDK für SAP ABAP
-
Anmerkung
Es gibt noch mehr GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-
einrichten und ausführen. " iv_vpc_id = 'vpc-abc123' " iv_service_name = 'com.amazonaws.region.service' TRY. oo_result = lo_ec2->createvpcendpoint( " oo_result is returned for testing purposes. " iv_vpcid = iv_vpc_id iv_servicename = iv_service_name it_routetableids = it_route_table_ids ). DATA(lv_vpc_endpoint_id) = oo_result->get_vpcendpoint( )->get_vpcendpointid( ). MESSAGE 'Created VPC endpoint.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Einzelheiten zur API finden Sie unter CreateVpcEndpoint in AWS SDK für SAP ABAP API-Referenz.
-
Für eine vollständige Liste von AWS SDK-Entwicklerhandbücher und Codebeispiele finden Sie unter EC2 Amazon-Ressourcen mithilfe eines AWS SDK erstellen. Dieses Thema enthält auch Informationen zu den ersten Schritten und Details zu früheren SDK-Versionen.