Interview Prep/Python for DevOps/AWS automation with boto3

You need to find every security group that allows 0.0.0.0/0 on any port other than 80 and 443. How do you write the check?

IntermediateScenarioAWS automation with boto3
Answer

Situation read → Port ranges and protocol -1 are the edge cases.

What I'd do →

  1. Paginate describe_security_groups.
  2. For each IpPermissions entry, check IpRanges[].CidrIp == "0.0.0.0/0" and Ipv6Ranges[].CidrIpv6 == "::/0".
  3. Handle IpProtocol == "-1" (all traffic, no port fields), and ranges (FromPort to ToPort) that include more than 80/443.
  4. Check whether the SG is attached (describe_network_interfaces with group-id filter) to prioritize.
allowed = {80, 443}
risky = proto == "-1" or not (lo == hi and lo in allowed)

Why → Rules like 0-65535 or protocol -1 are the most dangerous and the most commonly missed.

Interview tip → Mention IPv6; many audits forget ::/0.

All Python for DevOps questions Roadmap: Python for automation

More on AWS automation with boto3