Reputation: 281
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?
Upvotes: 10
Views: 5333
Reputation: 281
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 }] }
],
)
Upvotes: 12