How can I use boto3 to determine what subnet is private or public?

0

I am currently checking route tables to determine which routes are public or private.

However, I'm wondering if there's a way to call a subnet or determine what subnet has network firewalls in it. This will enable to be more confident on to which subnet is private (since our private subnets are pointing to network firewalls) and to check those route tables with that subnet id.

I was thinking this would be a better option opposed to just checking all the route tables inside the vpc. Any advice or suggestions will help.

Is there a way to use describe_network_interfaces to achieve this solution well?

2 Answers
1

Hello. Please see if this helps. 'MapPublicIpOnLaunch' in the Response when describe_subnets() is called.

MapPublicIpOnLaunch has a true/false value and indicates whether instances launched in this subnet receive a public IPv4 address.

Refer: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_subnets

AWS
answered a year ago
profile picture
EXPERT
reviewed 23 days ago
0

Hi, there is not a direct command that returns if your subnet is either private or public. You can use for instance the describe_subnets and get the subnet-id that the network firewall is using and the subnet-id that your instances are using and compare them. Another option can be: create a tag in your subnets where you identify subnets as private or public, and then with the same describe_subnets you can get tags and then know if these are private or public.

profile pictureAWS
answered a year ago
profile picture
EXPERT
reviewed 23 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions