I've a node.js program that is responsible to copy files from Bucket A belonging to Account A to Bucket B in Account B. How can I achieve this?
My program runs fine when both buckets are in the same account. Here is the snippet of code:
async function CopyMyFiles(fileID){
const s3 = new AWS.S3({
secretAccessKey: process.env.ACCESS_KEY,
accessKeyId: process.env.KEY_ID,
region: process.env.REGION,
});
const params = {
Bucket: BUCKET_DEST,
CopySource: "/" + BUCKET_SRC + "/" + fileID,
Key: fileID
};
await s3.copyObject(params, function(err, data) {
if (err) {
console.log('error', 'Error occured while copying', err);
}
else{
console.log("S3 file copied!");
}
});
}
My confusion is how to provide credentials to source and destination accounts here? Is just providing the CopySource enough in here for this cross-account scenario?