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개 답변
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
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전
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
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠