Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use boto3 authorize_security_group_ingress to add a rule between two security groups in non default VPC

I am trying to use boto3 to update security group rules, to add a rule to security group a (sg_a) to allow security group b (sg_b) to access port 8443.

I am trying to use EC2 client to achieve this with the following

ec2.authorize_security_group_ingress(
        GroupId=sg_a,
        SourceSecurityGroupName=sg_b,
        IpProtocol='tcp',
        FromPort=service_port,
        ToPort=service_port
    )

but I got this error:

botocore.exceptions.ClientError: An error occurred (VPCIdNotSpecified) when calling the AuthorizeSecurityGroupIngress operation: No default VPC for this user.

How do I use authorize_security_group_igress for a non-default VPC?

like image 869
blindstack Avatar asked May 03 '16 18:05

blindstack


1 Answers

the correct syntax is:

ec2.authorize_security_group_ingress( 
    GroupId=sg_a, 
    IpPermissions=[
        {'IpProtocol': 'tcp', 
        'FromPort': from_port, 
        'ToPort': to_port, 
        'UserIdGroupPairs': [{ 'GroupId': sg_b }] }
    ],
)
like image 103
blindstack Avatar answered Oct 07 '22 05:10

blindstack