Home > database >  Tagging S3 bucket object Issue
Tagging S3 bucket object Issue

Time:10-27

I am trying to add tags to existing object in S3 bucket using Lambda. Lambda has IAM role permission to add tags to bucket object, however simple python code to get_object_tagging is working but put_object_tagging is not working.

client = boto3.client("s3")            
tagresponse = client.put_object_tagging(
    Bucket="mybucket,
    Key="folder1/Test.txt",
    Tagging={'TagSet':[{'key':':permission:allowdownload','Value':'no'},{'key':'service:feature','Value':'sftpfiletransfer'}]},
        )

API response is throwing this error:

Parameter validation failed:
Missing required parameter in Tagging.TagSet[0]: "Key"
Unknown parameter in Tagging.TagSet[0]: "key", must be one of: Key, Value
Missing required parameter in Tagging.TagSet[1]: "Key"
Unknown parameter in Tagging.TagSet[1]: "key", must be one of: Key, Value
END RequestId: a45456e8-05c1-4b64-XXXX-XXXXXXXXXX

Key and Value pairs are populated as documentation but still not working.

Thanks in advance for your help.

CodePudding user response:

You need the uppercase K when supplying the tag-key:

client = boto3.client("s3")            
tagresponse = client.put_object_tagging(
    Bucket="mybucket,
    Key="folder1/Test.txt",
    Tagging={'TagSet':[{'Key':':permission:allowdownload','Value':'no'},{'Key':'service:feature','Value':'sftpfiletransfer'}]},
)

See the documentation here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_object_tagging

  • Related