简体   繁体   中英

How to put object tags on existing tagged object

I am currently developing Lambda functions using NodeJS and AWS S3 SDK.

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:

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.

In my code, I get the existing TagSet and update the values, then put them:

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. 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 .

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM