AWS SDK または CLI DeleteVpcで を使用する - Amazon Elastic Compute Cloud

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK または CLI DeleteVpcで を使用する

以下のコード例は、DeleteVpc の使用方法を示しています。

CLI
AWS CLI

VPC を削除するには

この例では、指定された VPC を削除します。コマンドが成功した場合、出力は返りません。

コマンド:

aws ec2 delete-vpc --vpc-id vpc-a01106c2
  • API の詳細については、「AWS CLI コマンドリファレンス」の「DeleteVpc」を参照してください。

PHP
SDK for PHP
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

/** * @param string $vpcId * @return void */ public function deleteVpc(string $vpcId) { try { $this->ec2Client->deleteVpc([ "VpcId" => $vpcId, ]); }catch(Ec2Exception $caught){ echo "There was a problem deleting the VPC: {$caught->getAwsErrorMessage()}\n"; throw $caught; } }
  • API の詳細については、「 API AWS SDK for PHP リファレンス」のDeleteVpc」を参照してください。

PowerShell
Tools for PowerShell

例 1: この例では、指定された VPC を削除します。Force パラメータも指定しない限り、操作が進む前に確認を求められます。

Remove-EC2Vpc -VpcId vpc-12345678

出力:

Confirm Are you sure you want to perform this action? Performing operation "Remove-EC2Vpc (DeleteVpc)" on Target "vpc-12345678". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
  • API の詳細については、AWS Tools for PowerShell 「 コマンドレットリファレンス」のDeleteVpc」を参照してください。

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(self, vpc_id: str) -> None: """ Deletes the specified VPC. :param vpc_id: The ID of the VPC to delete. """ try: self.ec2_client.delete_vpc(VpcId=vpc_id) except ClientError as err: logger.error( "Couldn't delete VPC %s. Here's why: %s: %s", vpc_id, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • API の詳細については、 AWS SDK for Python (Boto3) API リファレンスDeleteVpc」を参照してください。

AWS SDK 開発者ガイドとコード例の完全なリストについては、「」を参照してくださいを使用して Amazon EC2リソースを作成する AWS SDK。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。