Boto3:如果我知道安全组名称,如何查找安全组ID

7

我正在尝试通过名称查找安全组 ID。response = ec2.describe_security_groups() 返回一个包含所有组、ID 和其他信息的数据结构。如果提供了组名,如何过滤特定组的组 ID?

1个回答

16
用你要查找的安全组名称替换GROUP_NAME:
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']


1
我想使用AWS CDK Typescript找到相同的东西。 - Ashish Karpe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接