我正在尝试按名称查找安全组 ID。response = ec2.describe_security_groups() 返回一个数据结构,其中包括所有组、ID 和其他所有内容。如果提供了组名,过滤特定组的组 ID 的方法是什么?
替换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']
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2271 次 |
| 最近记录: |