Skip to main content
 首页 » 编程设计

python之如何将新创建的 EC2 安全组与实例相关联

2025年04月02日17zengkefu

如何将 EC2 实例添加到新创建的安全组?安全组创建于

client = session.client("ec2") 
group_id = client.create_security_group( 
    DryRun=False, 
    GroupName=group_name, 
    VpcId=vpc_id, 
    Description=description 
) 

请您参考如下方法:

您将要修改实例的属性:

modify_attribute(attribute, value, dry_run=False) 

modify_attribute 更改此实例的属性。使用属性 groupSet - 安全组或 ID 集

i.modify_attribute('groupSet','sg-xxxx5678') 

参见 boto.ec2.instance