FG
☁️ Cloud & DevOpsAmazon

add --all-dependencies option to ec2 delete-vpc

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Feature request support `aws ec2 delete-vpc --all-dependencies --vpc-id vpc-deadbeef` Details The AWS web console will delete a VPC along with all its dependencies. The `aws` cli tool says (when trying to delete a VPC with any dependencies): `A client error (DependencyViolation) occurred when calling the DeleteVpc operation: The vpc 'vpc-deadbeef' has dependencies and cannot be deleted.` 1. Subnets 2. Security Groups 3. Network ACLs 4. VPN Attachments 5. Internet Gateways 6. Route Tables 7. Network Interfaces 8. VPC Peering Connections Maybe also add `--vpn-connection`.

Error Output

error (DependencyViolation) occurred when calling the DeleteVpc operation: The vpc 'vpc-deadbeef' has dependencies and cannot be deleted.`

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Implement --all-dependencies Option for EC2 Delete VPC Command

Medium Risk

The AWS CLI does not currently support a command to delete a VPC along with all its dependencies, which leads to a DependencyViolation error when attempting to delete a VPC that has associated resources such as subnets, security groups, and more.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify Dependencies

    Before deleting the VPC, identify all associated resources that need to be deleted. This includes subnets, security groups, network ACLs, VPN attachments, internet gateways, route tables, network interfaces, and VPC peering connections.

    bash
    aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-deadbeef
    aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-deadbeef
    aws ec2 describe-network-acls --filters Name=vpc-id,Values=vpc-deadbeef
  2. 2

    Delete Dependencies

    Execute commands to delete each identified dependency before attempting to delete the VPC. Ensure to handle each resource type appropriately, as some may require specific deletion sequences.

    bash
    aws ec2 delete-subnet --subnet-id subnet-12345678
    aws ec2 delete-security-group --group-id sg-12345678
    aws ec2 detach-internet-gateway --internet-gateway-id igw-12345678 --vpc-id vpc-deadbeef
    aws ec2 delete-internet-gateway --internet-gateway-id igw-12345678
  3. 3

    Delete the VPC

    Once all dependencies have been removed, proceed to delete the VPC using the AWS CLI. This should now succeed without any DependencyViolation errors.

    bash
    aws ec2 delete-vpc --vpc-id vpc-deadbeef
  4. 4

    Add --all-dependencies Option

    Propose an enhancement to the AWS CLI to include an --all-dependencies option that automates the deletion of all dependencies when a VPC is deleted. This would streamline the process and reduce the risk of errors.

    bash
    aws ec2 delete-vpc --all-dependencies --vpc-id vpc-deadbeef

Validation

Confirm that the VPC has been deleted successfully by running 'aws ec2 describe-vpcs --vpc-ids vpc-deadbeef'. The command should return an error indicating that the VPC does not exist.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

awsclicloudfeature-requestec2