> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Default VPC Should Not Be In Use

### More Info:

It is recommended not to using the default VPC.

### Risk Level

Medium

### Address

Security

### Compliance Standards

GDPR, SOC2, NISTCSF

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        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.

        #
      </Accordion>

      <Accordion title="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.
      </Accordion>

      <Accordion title="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:

        ```python theme={null}
        import boto3
        ```

        2. Create a new EC2 resource object:

        ```python theme={null}
        ec2 = boto3.resource('ec2')
        ```

        3. Get a list of all VPCs in the AWS account:

        ```python theme={null}
        vpcs = list(ec2.vpcs.all())
        ```

        4. Loop through the list of VPCs and check if any of them are the default VPC:

        ```python theme={null}
        for vpc in vpcs:
            if vpc.is_default:
                # Remediate the default VPC
        ```

        5. 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:

        ```python theme={null}
        vpc.delete()
        ```

        6. 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:

        ```python theme={null}
        vpc.modify_attribute(Default='false')
        ```

        7. Finally, you can confirm that the default VPC has been remediated by checking the list of VPCs again:

        ```python theme={null}
        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.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/default-vpc.html](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/default-vpc.html)
