Skip to content

delete_vpc

delete_vpc(
    *,
    config_overrides: Optional[EC2ClientConfig] = 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.

>>> client.delete_vpc(vpc_id='vpc-a01106c2')
Source code in docs_src/capo_ec2/_services/ec2.py
def delete_vpc(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = 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.

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

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

        output, http_response = (
            capo_ec2._operations.amazon_ec2.delete_vpc.delete_vpc(
                req.options, req.input
            )
        )
        return OperationResponse(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 = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output