EC2 instance uses the default VPC

Verify the EC2 instance’s actual VPC and subnet, and apply the isolation, routing and security groups required by the workload.

Description

Check that SubnetId selects a subnet in the intended VPC.

Potential impact

Workloads sharing the default VPC may be able to reach one another. A public address, an internet route, and permissive security group rules can also make the instance reachable from the internet.

Remediation

  1. Set SubnetId to a subnet that meets the workload’s isolation requirements.
  2. Check its routes, public IP assignment, and security group rules.
  3. Review the change set for instance replacement and plan for any interruption.

Examples

Use an AMI for the target Region. Check which subnets DefaultSubnet and PrivateSubnet actually reference.

Before

yaml
Resources:
  AppInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-79fd7eee
      SubnetId: !Ref DefaultSubnet

After

yaml
Resources:
  AppInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-79fd7eee
      SubnetId: !Ref PrivateSubnet

References