I have an application which upload ( copy ) some files to a S3 bucket in another AWS account, I use copyObject command from AWS SDK ( Nodejs )
var params = {
Bucket: "MyBucket_AccountB",
CopySource: encodeURI('/Accunt_A_Bocket/file.png'),
Key: "file.png",
ACL: 'bucket-owner-full-control'
};
s3.copyObject(params, function(err, datas) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(datas); // successful response
});
This code, run from a diffrent AWS Account, let's say, AWS_ACCOUNT_A
, and the files uploaded to a S3 bucket in AWS_ACCOUNT_B
The thing is, when it upload the files to this bucket, the ownership of this files, are still AWS_ACCOUNT_A
.
I want to know what should I do to give ownership of files to AWS_ACCOUNT_B
, while uploading them. Anyone here can give me some guidance?
UPDATE :
I used this policy :
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::MY_ACCOUNT_B_ID:root"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::MYBUCKET_IN_ACCOUNT_A",
"arn:aws:s3:::MYBUCKET_IN_ACCOUNT_A/*"
]
}
]
}
but the uploaded files are still owned by Account_A
, Did I do anything wrong in the policy?