AWS SDK または CLI で DeleteVpcEndpoints を使用する
次のサンプルコードは、DeleteVpcEndpoints を使用する方法を説明しています。
アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。
- CLI
-
- AWS CLI
-
エンドポイントを削除するには
この例では、エンドポイント vpce-aa22bb33 と vpce-1a2b3c4d を削除します。コマンドが部分的に成功または失敗した場合は、失敗した項目のリストが返されます。コマンドが成功した場合、返されたリストは空になります。
コマンド:
aws ec2 delete-vpc-endpoints --vpc-endpoint-idsvpce-aa22bb33vpce-1a2b3c4d出力:
{ "Unsuccessful": [] }-
API の詳細については、「AWS CLI コマンドリファレンス」の「DeleteVpcEndpoints
」を参照してください。
-
- PHP
-
- SDK for PHP
-
注記
GitHub には、その他のリソースもあります。AWS コード例リポジトリ
で全く同じ例を見つけて、設定と実行の方法を確認してください。 /** * @param string $vpcEndpointId * @return void */ public function deleteVpcEndpoint(string $vpcEndpointId) { try { $this->ec2Client->deleteVpcEndpoints([ "VpcEndpointIds" => [$vpcEndpointId], ]); }catch (Ec2Exception $caught){ echo "There was a problem deleting the VPC Endpoint: {$caught->getAwsErrorMessage()}\n"; throw $caught; } }-
API の詳細については、「AWS SDK for PHP API リファレンス」の「DeleteVpcEndpoints」を参照してください。
-
- 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 delete_vpc_endpoints(self, vpc_endpoint_ids: list[str]) -> None: """ Deletes the specified VPC endpoints. :param vpc_endpoint_ids: A list of IDs of the VPC endpoints to delete. """ try: self.ec2_client.delete_vpc_endpoints(VpcEndpointIds=vpc_endpoint_ids) except ClientError as err: logger.error( "Couldn't delete VPC endpoints %s. Here's why: %s: %s", vpc_endpoint_ids, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise-
API の詳細については、「AWS SDK for Python (Boto3) API リファレンス」の「DeleteVpcEndpoints」を参照してください。
-
AWS SDK デベロッパーガイドとコード例の詳細なリストについては、「AWS SDK を使用して Amazon EC2 リソースを作成する」を参照してください。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。