Boto3 command to access VPC

Category: Manage AWS using Python: Core ServicesBoto3 command to access VPC
Ram asked 9 months ago
Please let me know the Boto3 script to list the Security groups inside a VPC with CIDR block say \’\’. Also how can I filter the security groups based on it\’s source Ip address.
1 Answers
Best Answer
Karan Brar Staff answered 9 months ago
If you don’t know your VPC ID then make a client connection with EC2 and get the VPC ID  ec2_client=boto3.client(‘ec2’) ec2_client.describe_vpcs()   After that, make a resource connection with EC2 and then get the details of VPC by using the VPC ID you captured in first step.   ec2_res=boto3.resource(‘ec2’) vpc_conn=ec2_res.Vpc(‘VPC_ID’) vpc_sg=vpc_conn.security_groups.all()   That will make iterable collection of Security Group parameters in a given VPC ID