More Info:

It is recommended not to using the default VPC.

Risk Level

Medium

Address

Security

Compliance Standards

GDPR, SOC2, NISTCSF

Remediation

Using Console

To remediate the “Default VPC Should Not Be In Use” misconfiguration in AWS, you can follow these steps:

  1. Log in to the AWS Management Console.

  2. Open the Amazon VPC console.

  3. In the navigation pane, select “Your VPCs”.

  4. Identify the default VPC. The default VPC has the “Default VPC” tag.

  5. Select the default VPC.

  6. Choose “Actions”, and then choose “Delete VPC”.

  7. In the confirmation dialog box, choose “Delete VPC”.

  8. If you have any resources running in the default VPC, you will need to move them to a new VPC before you can delete the default VPC. To do this, follow these steps:

    a. In the navigation pane, select the resource type (such as EC2 instances or RDS instances).

    b. Select the resource that is running in the default VPC.

    c. Choose “Actions”, and then choose “Create Image” (for EC2 instances) or “Create Snapshot” (for RDS instances).

    d. After the image or snapshot is created, launch a new instance or RDS instance in a new VPC.

  9. After you have moved all resources out of the default VPC, repeat steps 5-7 to delete the default VPC.

  10. Once the default VPC is deleted, you should create a new VPC and configure it according to your requirements.

Using CLI

To remediate the misconfiguration of using the Default VPC in AWS, follow these steps:

  1. Open the AWS CLI on your local machine or in the AWS Management Console.

  2. Run the following command to list all the VPCs in your account:

    aws ec2 describe-vpcs
    
  3. Identify the Default VPC in the output. The Default VPC has the isDefault attribute set to true.

  4. Run the following command to delete the Default VPC:

    aws ec2 delete-vpc --vpc-id <vpc-id>
    

    Replace <vpc-id> with the ID of the Default VPC that you want to delete.

  5. Confirm the deletion by entering y when prompted.

  6. Once the Default VPC is deleted, you will need to create a new VPC and configure it according to your requirements.

    aws ec2 create-vpc --cidr-block <cidr-block>
    

    Replace <cidr-block> with the CIDR block that you want to assign to the new VPC.

  7. Configure the VPC by adding subnets, route tables, security groups, and any other required resources.

  8. Once the VPC is configured, launch your instances in the new VPC instead of the Default VPC.

By following these steps, you can remediate the misconfiguration of using the Default VPC in AWS.

Using Python

To remediate the “Default VPC Should Not Be In Use” misconfiguration in AWS using Python, follow these steps:

  1. Import the necessary AWS SDK libraries for Python:
import boto3
  1. Create a new EC2 resource object:
ec2 = boto3.resource('ec2')
  1. Get a list of all VPCs in the AWS account:
vpcs = list(ec2.vpcs.all())
  1. Loop through the list of VPCs and check if any of them are the default VPC:
for vpc in vpcs:
    if vpc.is_default:
        # Remediate the default VPC
  1. If a default VPC is found, you can either delete it or modify it to remove the default status. To delete the default VPC, use the following code:
vpc.delete()
  1. Alternatively, you can modify the default VPC to remove the default status. To do this, you need to modify the “is_default” attribute of the VPC:
vpc.modify_attribute(Default='false')
  1. Finally, you can confirm that the default VPC has been remediated by checking the list of VPCs again:
vpcs = list(ec2.vpcs.all())
for vpc in vpcs:
    if vpc.is_default:
        print("Default VPC still exists")

This should remediate the “Default VPC Should Not Be In Use” misconfiguration in AWS using Python.

Additional Reading: