Gunakan DeleteVpc dengan AWS SDK atau CLI - Amazon Elastic Compute Cloud

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan DeleteVpc dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanDeleteVpc.

CLI
AWS CLI

Untuk menghapus VPC

Contoh ini menghapus VPC yang ditentukan. Jika perintah berhasil, tidak ada output yang akan ditampilkan.

Perintah:

aws ec2 delete-vpc --vpc-id vpc-a01106c2
  • Untuk detail API, lihat DeleteVpcdi Referensi AWS CLI Perintah.

PHP
SDK untuk PHP
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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; } }
  • Untuk detail API, lihat DeleteVpcdi Referensi AWS SDK for PHP API.

PowerShell
Alat untuk PowerShell

Contoh 1: Contoh ini menghapus VPC yang ditentukan. Anda diminta untuk konfirmasi sebelum operasi berlangsung, kecuali jika Anda juga menentukan parameter Force.

Remove-EC2Vpc -VpcId vpc-12345678

Output:

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"):
  • Untuk detail API, lihat DeleteVpcdi Referensi Alat AWS untuk PowerShell Cmdlet.

Python
SDK untuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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
  • Untuk detail API, lihat DeleteVpcdi AWS SDK for Python (Boto3) Referensi API.

Untuk daftar lengkap panduan pengembang AWS SDK dan contoh kode, lihatMembuat EC2 sumber daya Amazon menggunakan AWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang versi SDK sebelumnya.