I would like to ask about 'AWS get Federation Token'.
What I want to do is that someone authorized by using getFederationToken could access ONLY HIS/HER NAMED AWS S3 folder like [bob] or [alice], etc.
Here is what I've done.
Make Temporary Credentials by using getFederationToken for aws:userid
AWS.config.update({
accessKeyId: [Removed],
secreteAccessKey: [Removed],
region: [Removed]
});
var params = {
Name : 'bob',
Policy : "{\"Version\": \"2012-10-17\",\"Statement\": [{\"Effect\": \"Allow\", \"Action\": [\"s3:ListBucket\"],\"Resource\": [\"arn:aws:s3:::mybucket\"]}, {\"Effect\": \"Allow\", \"Action\": [\"s3:PutObject\", \"s3:GetObject\"],\"Resource\": [\"arn:aws:s3:::mybucket/${aws:userid}/*\"]}]}",
DurationSeconds: "129600"
}
var sts = new AWS.STS({apiVersion: '2011-06-15'});
sts.getFederationToken(params, function(err, data) {
if(err)
console.log(err, err.stack);
else
console.log(data);
});
But I don't know what will be called from ${aws:userid}. AWS User Guide say that [account:caller-specified-name] will be called when the principal is Federated user... However, I checked whether it's [AWS account ID (12-digit number):bob]. It's not..
If you have something to tell me, plz let me know. Thank you.
I've found a solution even not perfect.
[account:caller-specified-name] is working correctly as [123456789012:bob] only with s3 policy, not JS code parameter.