I'm uploading the contents of a file to s3 using the Put Object endpoint and attempting to use the x-amz-tagging request header.
See documentation here: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html.
As in example 6 in the link above:
Example 6: Upload an Object and Specify Tags
In this upload object request, you specify the optional x-amz-taggging header to add tags to the object.
Copy PUT /example-object HTTP/1.1 Host: example-bucket.s3.amazonaws.com Accept: /
Authorization:authorization string Date: Thu, 22 Sep 2016 21:58:13 GMT x-amz-tagging: tag1=value1&tag2=value2[... bytes of object data]
I generate a base string like so used to generate the authorization string:
String baseString = "PUT\n\ntext/plain\n"
+ currentDate + "\n"
+ "x-amz-tagging:tag1=value1&tag2=value2" + "\n"
+ "/" + LOG_BUCKET_NAME + THE_REST_OF_THE_URL;
Then build my request like so:
request.setRawHeader("Date", currentDate);
request.setRawHeader("Authorization", authorizationString);
request.setRawHeader("x-amz-tagging", "tag1=value&tag2=value2);
I get a forbidden error every time but adding metadata works perfectly:
Base string:
String baseString = "PUT\n\ntext/plain\n"
+ currentDate + "\n"
+ "x-amz-meta-reviewedby:my_email@domain.com" + "\n"
+ "/" + LOG_BUCKET_NAME + THE_REST_OF_THE_URL;
And then:
request.setRawHeader("Date", currentDate);
request.setRawHeader("Authorization", authorizationString);
request.setRawHeader("X-Amz-Meta-ReviewedBy", "my_email@domain.com");
Is there perhaps additional user permissions required for adding tags?
It was in fact a permissions issue. The fix involved enabling user permissions for Object Tagging.