Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Rule: EC2 Instances Should Be in a VPC

Guideline outlining that all EC2 instances must be placed within a Virtual Private Cloud

RuleEC2 instances should be in a VPC
FrameworkCISA-cyber-essentials
Severity
High

EC2 instances should be in a VPC for CISA-Cyber-Essentials

Description:

CISA (Cybersecurity and Infrastructure Security Agency) recommends that all EC2 instances should be deployed within a Virtual Private Cloud (VPC) to enhance security and protect your resources from unauthorized access. A VPC provides a logically isolated network environment where you can launch and manage your AWS resources in a secure manner. By properly configuring your EC2 instances within a VPC, you can establish granular control over network security and implement additional security measures.

Troubleshooting Steps (if applicable):

  • If an EC2 instance is not within a VPC, you need to follow these steps to move it to a VPC:
    1. 1.
      Identify the EC2 instance that is not within a VPC.
    2. 2.
      Create a new VPC or use an existing VPC to host the instance.
    3. 3.
      Launch a new EC2 instance within the desired VPC.
    4. 4.
      Migrate any necessary data or configurations from the old instance to the new instance.
    5. 5.
      Update DNS settings or any other dependent resources to point to the new instance.
    6. 6.
      Terminate the old instance outside the VPC once you have verified the successful migration.

Note: Before proceeding, ensure that you have a good understanding of VPCs, security groups, and networking concepts within AWS. Make sure to create proper backups and test the migration in a non-production environment before migrating critical instances.

Necessary Codes (if applicable):

We will use the AWS Command Line Interface (AWS CLI) to demonstrate the necessary commands for moving an EC2 instance to a VPC.

  1. 1.
    Create a new VPC:
aws ec2 create-vpc --cidr-block <desired_cidr_block>
  1. 1.
    Launch a new EC2 instance within the VPC:
aws ec2 run-instances --image-id <desired_ami_id> --count <number_of_instances> --instance-type <desired_instance_type> --subnet-id <desired_subnet_id>
  1. 1.

    Migrate any necessary data or configurations from the old instance to the new instance.

  2. 2.

    Update DNS settings or any other dependent resources to point to the new instance.

  3. 3.

    Terminate the old instance outside the VPC:

aws ec2 terminate-instances --instance-ids <old_instance_id>

Step-by-Step Guide for Remediation:

Follow the steps below to move an EC2 instance to a VPC:

  1. 1.

    Identify the EC2 instance that is not within a VPC by navigating to the EC2 Dashboard in the AWS Management Console.

  2. 2.

    Create a new VPC by going to the VPC Dashboard and selecting "Create VPC." Specify the desired CIDR block for the VPC and click on "Create."

  3. 3.

    Launch a new EC2 instance within the VPC. Go to the EC2 Dashboard and click on "Launch Instance." Select the desired AMI, Instance Type, and other configurations. In the "Configure Instance Details" section, select the newly created VPC and choose a suitable subnet within the VPC. Proceed with the launch process.

  4. 4.

    Migrate any necessary data or configurations from the old instance to the new instance. This may include copying files, updating configurations, or transferring database data.

  5. 5.

    Update DNS settings or any other dependent resources to point to the new instance. Modify any records or configurations accordingly.

  6. 6.

    Once you have verified the successful migration and ensured everything is functioning as expected, terminate the old instance outside the VPC. Go to the EC2 Dashboard, find the old instance, select it, and click on "Actions" > "Instance State" > "Terminate." Confirm the termination when prompted.

By following these steps, you will successfully move your EC2 instance to a VPC, aligning with CISA-Cyber-Essentials security recommendations. Remember to document the changes made and regularly review and update security measures as per best practices.

Is your System Free of Underlying Vulnerabilities?
Find Out Now