Vijay Kumar
Vijay Kumar

Reputation: 2717

Error when creating an ELB in AWS using boto3

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

Answers (1)

Rodrigo Murillo
Rodrigo Murillo

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

Related Questions