Copying files from one folder to another folder in s3 of the same NODE JS bucket

I try to copy a file from one folder to another folder in the same bucket, but I get gettnin Access denined error. But if I try to do this on two different buckets, it means that it works great.

Please find what I have tried so far below:

var AWS = require('aws-sdk');
AWS.config.update({
     accessKeyId: 'xxx',
     secretAccessKey: 'xxx'
    });
var s3 = new AWS.S3();
var params = {
    Bucket : 'bucketname', /* Another bucket working fine */ 
    CopySource : 'bucketname/externall/1.txt', /* required */
    Key : "1.txt", /* required */
    ACL : 'public-read',
};
s3.copyObject(params, function(err, data) {
    if (err)
        console.log(err, err); // an error occurred
    else {
        console.log(data); // successful response
    }
});
+4
source share
1 answer

I used the same copyObject method and used the same bucket name in the source and destination paths, it worked. below is my sample code

{
    Bucket: bucketName,
    CopySource: '/'+bucketName+'/local/Country.png',
    Key: 'local/copy-Country.png'
}
+1
source

Source: https://habr.com/ru/post/1606214/


All Articles