[英]boto3 how to get all tags for a single ec2 instance and append new ones
My task would seem to be simple but I am not seeing in the documentation nor on the web. I have an ec2 instance id and I want to get all the currents tags and add additional ones.我的任务似乎很简单,但我没有在文档中看到,也没有在 web 上看到。我有一个 ec2 实例 ID,我想获取所有电流标签并添加其他标签。 All I see for examples is how to get all instances running or in a vpc.
我所看到的示例是如何让所有实例运行或在 vpc 中运行。 The boto2 document only shows how to retrieve a single tag or multiple but not all.
boto2 文档仅显示如何检索单个标签或多个但不是全部。
These days, you should be using boto3 .这些天,您应该使用boto3 。
To retrieve the tags of an instance, use describe_instances()
.要检索实例的标签,请使用
describe_instances()
。
It returns:它返回:
{
'Reservations': [
{
'Instances': [
{
'Tags': [
{
'Key': 'string',
'Value': 'string'
},
To set the tags on an instance, use create_tags()
, specifying the ID of the instance.要在实例上设置标签,请使用
create_tags()
,指定实例的 ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.