I am trying to find security group id by name. response = ec2.describe_security_groups() returns a data structure which includes all groups, ids and everything else. What is the way to filter group id for specific group if group name is provided?
Replace GROUP_NAME
with the security group name you are looking for:
import boto3
ec2 = boto3.client('ec2')
group_name = 'GROUP_NAME'
response = ec2.describe_security_groups(
Filters=[
dict(Name='group-name', Values=[group_name])
]
)
group_id = response['SecurityGroups'][0]['GroupId']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With