Skip to content

delete_vpc async

delete_vpc(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    vpc_id: Optional[VpcId] = None,
    dry_run: Optional[Boolean] = None,
) -> None

Deletes the specified VPC. You must detach or delete all gateways and resources that are associated with the VPC before you can delete it. For example, you must terminate all instances running in the VPC, delete all security groups associated with the VPC (except the default one), delete all route tables associated with the VPC (except the default one), and so on. When you delete the VPC, it deletes the default security group, network ACL, and route table for the VPC.

If you created a flow log for the VPC that you are deleting, note that flow logs for deleted VPCs are eventually automatically removed.

Parameters:

  • vpc_id (Optional[VpcId], default: None ) –

    The ID of the VPC.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Raises:

Examples:

To delete a VPC This example deletes the specified VPC.

>>> await client.delete_vpc(vpc_id='vpc-a01106c2')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def delete_vpc(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    vpc_id: Optional["capo_ec2.types.vpc_id.VpcId"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> None:
    """<p>Deletes the specified VPC. You must detach or delete all gateways and resources that are associated with the VPC before you can delete it. For example, you must terminate all instances running in the VPC, delete all security groups associated with the VPC (except the default one), delete all route tables associated with the VPC (except the default one), and so on. When you delete the VPC, it deletes the default security group, network ACL, and route table for the VPC.</p> <p>If you created a flow log for the VPC that you are deleting, note that flow logs for deleted VPCs are eventually automatically removed.</p>

    Args:
        vpc_id: <p>The ID of the VPC.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a VPC
        This example deletes the specified VPC.

        >>> await client.delete_vpc(vpc_id='vpc-a01106c2')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.delete_vpc_request.DeleteVpcRequest]",
    ) -> AsyncOperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.delete_vpc

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.delete_vpc.async_delete_vpc(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteVpc")
    )
    input_: capo_ec2.types.delete_vpc_request.DeleteVpcRequest = {}
    if vpc_id is not None:
        input_["vpc_id"] = vpc_id
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output