使用boto3创建EBS快照时添加标签 [英] Add tag while creating EBS snapshot using boto3

查看:150
本文介绍了使用boto3创建EBS快照时添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在boto3中调用create_snapshot()方法时是否可以添加标签?当我运行以下代码时:

  client = boto3.client('ec2')

root_snap_resp = client.create_snapshot(
Description ='我的快照描述',
VolumeId ='vol-123456',
标签= [{'Key':'Test_Key','Value':' Test_Value'}]

我收到以下错误:

  botocore.exceptions.ParamValidationError:参数验证失败:
输入中的未知参数: Tags,必须为DryRun,VolumeId,说明

是在事实​​之后使用create_tags()方法添加标签的唯一方法吗?

解决方案

在2018年4月,原始答案(和问题本身)已过时...


现在,您可以为EBS快照指定标签,作为创建资源的API调用的一部分,或者在创建EBS快照时通过Amazon EC2控制台。



https://aws.amazon.com/ Blogs / compute / tag-amazon-ebs-snapshots-on-creation-and-implement-strong-security-policies /


...除非您使用的是未实现此功能的SDK的较早版本。



同一条公告将资源级权限扩展到快照。 / p>

基础 EC2 API中的 CreateSnapshot 操作没有任何规定可在创建快照的同时添加标签。创建后,您必须返回并对其进行标记。


Is it possible to add a tag when invoking the create_snapshot() method in boto3? When I run the following code:

client = boto3.client('ec2')

root_snap_resp = client.create_snapshot(
    Description='My snapshot description',
    VolumeId='vol-123456',
    Tags=[{'Key': 'Test_Key', 'Value': 'Test_Value'}]
)

I get the following error:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "Tags", must be one of: DryRun, VolumeId, Description

Is the only way to add a tag after the fact using the create_tags() method?

解决方案

In April, 2018, the original answer (and the question itself) were made obsolete...

You can now specify tags for EBS snapshots as part of the API call that creates the resource or via the Amazon EC2 Console when creating an EBS snapshot.

https://aws.amazon.com/blogs/compute/tag-amazon-ebs-snapshots-on-creation-and-implement-stronger-security-policies/

...unless you are using an older version of an SDK that does not implement the feature.

The same announcement extended resource-level permissions to snapshots.

The underlying CreateSnapshot action in the EC2 API doesn't have any provision for adding tags simultaneously with the creation of the snapshot. You have to go back and tag it after creating it.

这篇关于使用boto3创建EBS快照时添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆