I am using AWS STS Federation Token to get temporary credentials, with below statement.
Statement putStatement = new Statement(Statement.Effect.Allow)
.withId("TempCreds")
.withActions(S3Actions.PutObject)
.withResources(new S3ObjectResource(bucketName, "*"));
Now I am able to get temp creds, but when I am uploading a file using PutObjectRequest
:
s3Client.putObject(new PutObjectRequest(bucketName, keyName, file));
but this is default PRIVATE ACL. Question is how to set PUBLIC ACL?
because when i use below code,
s3Client.putObject(new PutObjectRequest(bucketName, keyName, file)
.withCannedAcl(CannedAccessControlList.PublicRead));
the upload fails.
If in the above statement for Getting federation token, I add ACL like below
Statement putStatement = new Statement(Statement.Effect.Allow)
.withId("TempCreds")
.withActions(S3Actions.PutObject)
.withResources(new S3ObjectResource(bucketName, "*"))
.withConditions(S3ConditionFactory.newCannedACLCondition(CannedAccessControlList.PublicRead));
the upload still fails.
So how to set Public ACL when using Short term credentials?
I have given below policy to the IAM User, which is going to generate STS.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1507714071000",
"Effect": "Allow",
"Action": [
"sts:GetFederationToken"
],
"Resource": [
"*"
]
}
]
}