Description
Check whether an internal EC2 instance needs a public IPv4 address. An internet gateway route and permissive network rules can make a listening service reachable from the internet.
Potential impact
A publicly reachable service or management port can receive unwanted sign-in attempts or allow unauthorized access.
Remediation
- Prepare the paths you need. Use a load balancer for a public service, a VPN or Systems Manager for administration, and a NAT gateway for outbound internet access as appropriate.
- For a new internal instance, select a private subnet and set
assign_public_iptofalse. Limit security groups and network ACLs to required traffic. - Review existing interface addresses, Elastic IPs, and IPv6 routes separately. Test application and management connectivity.
Examples
These tasks use the older network setting. With amazon.aws 8.2.0 or later, a launch that creates a single primary interface can set assign_public_ip on its network_interfaces entry. Supply your image, subnet, and security groups.
Before
yaml
- name: start an instance with a public IP address
community.aws.ec2_instance:
name: public-compute-instance
vpc_subnet_id: subnet-5ca1ab1e
instance_type: c5.large
network:
assign_public_ip: true
After
yaml
- name: start an instance without a public IP address
community.aws.ec2_instance:
name: private-compute-instance
vpc_subnet_id: subnet-5ca1ab1e
instance_type: c5.large
network:
assign_public_ip: false
The tasks launch differently named instances in the same subnet. Review existing instances separately.