我正在使用 boto 库并能够获取我的 ec2 实例的标签值,但是无法更新它们的值。
谁能帮忙解决如何使用 boto 库更新/更改经典 EC2 实例的标签值?
谢谢!
请您参考如下方法:
在 EC2 实例上添加和删除标签在 boto 中非常容易。假设您有一个 ID 为 i-12345678 的实例,并且您想要将标签 foo=bar 添加到该实例。
import boto.ec2
c = boto.ec2.connect_to_region('us-west-2')
reservations = c.get_all_instances(instance_ids='i-12345678')
instance = reservations[0].instances[0]
instance.add_tag('foo', 'bar')
删除标签:
instance.remove_tag('foo', 'bar')
第二个参数是标签的值,是可选的。
