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
- Set
SubnetIdto a subnet that meets the workload’s isolation requirements. - Check its routes, public IP assignment, and security group rules.
- 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