[英]How to put object tags on existing tagged object
I am currently developing Lambda functions using NodeJS and AWS S3 SDK.我目前正在使用 NodeJS 和 AWS S3 SDK 开发 Lambda 函数。
While working local with serverless offline, I can easily replace an object TagSet with putObjectTagging
function, but in Production environment, I do have this error:在本地使用无服务器离线工作时,我可以轻松地将 object TagSet 替换为putObjectTagging
function,但在生产环境中,我确实遇到此错误:
Cannot provide multiple Tags with the same key不能提供具有相同键的多个标签
While reading putObjectTagging
and AWS tags documentation, I do not find any solution for this error because I do presume that putObjectTagging
replace all tags of an existing object.在阅读putObjectTagging
和 AWS 标签文档时,我没有找到针对此错误的任何解决方案,因为我确实假设putObjectTagging
替换了现有 object 的所有标签。
In my code, I get the existing TagSet and update the values, then put them:在我的代码中,我获取现有的 TagSet 并更新值,然后将它们放入:
let tags = await S3.getObjectTagging(bucketParam).promise();
// process on tags and set in paramsPutObjectTagging
await S3.putObjectTagging(paramsPutObjectTagging).promise();
Thank you in advance, Regards.提前谢谢你, 问候。
The s3:PutObjectTagging
call will replace any existing TagSet
on the object with the TagSet
provided in the call. s3:PutObjectTagging
调用将用调用中提供的 TagSet 替换TagSet
上的任何现有TagSet
。 Although the TagSet
attribute in the request body for the call is an array, the Key
attribute of every item in the array must be distinct, you cannot have duplicate Key
s in the TagSet
.虽然调用请求体中的TagSet
属性是一个数组,但是数组中每一项的Key
属性必须是不同的, TagSet
中不能有重复的Key
。
To add a new tag to an object whilst preserving the existing tags that are there you need to retrieve the existing TagSet
using s3:GetObjectTagging
, then append the new tag to the TagSet
array, then use s3:PutObjectTagging
as described above.要向 object 添加新标签,同时保留现有标签,您需要使用s3:GetObjectTagging
检索现有TagSet
,然后 append 将新标签添加到TagSet
数组,然后如上所述使用s3:PutObjectTagging
。 When doing this you need to check that there isn't already a tag in the TagSet
retrieved from s3:GetObjectTagging
with the same Key
as the new tag you're trying to add - this is likely to be why you are getting that error.执行此操作时,您需要检查从s3:GetObjectTagging
检索到的TagSet
中是否还没有与您尝试添加的新标签具有相同Key
的标签 - 这可能就是您收到该错误的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.