Reputation: 2717
How do I get a list of security groups in a non default VPC? I create a VPC and then create security groups in it. Later in the code I need to find a security group by name, so I do a describe_security_groups() call, but I am getting this error, as the code is only listing security groups in the default VPC.
EXCEPTION An error occurred (InvalidGroup.NotFound) when calling the DescribeSecurityGroups operation: The security group 'elb_security_group' does not exist in default VPC 'vpc-4e39c02b'
Upvotes: 0
Views: 215
Reputation: 13638
You can get a list of the security groups available in a given VPC using the security_groups collection
import boto3
ec2 = boto3.resource('ec2')
vpc = ec2.Vpc('id')
security_group_iterator = vpc.security_groups.all()
Upvotes: 1