skip to Main Content

I’m calling the copyObject method of aws-sdk v2 ‘s S3 class:

const s3 = new AWS.S3({...s3Config});
// attempt 1
let copyObject = {
    Bucket: 'my-bucket-name',
    CopySource: `s3://my-bucket-name/my/file/path`,
    Key: `/my/destination/path`,
}

await s3.copyObject(copyObj);

// attempt 2
copyObject = {
    Bucket: 'my-bucket-name',
    CopySource: `my-bucket-name/my/file/path`,
    Key: `/my/destination/path`,
}

await s3.copyObject(copyObj);

Both fail with the same error:

Cannot read property 'appendToUserAgent' of undefined

Pointing to at promise (/src/node_modules/aws-sdk/lib/request.js:780:22). Am I missing something here? I referred to this documentation:

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#copyObject-property

2

Answers


  1. Chosen as BEST ANSWER

    Looking at Dzmitry Luhauskoi's answer, I realized that I was using the .promise in a for loop among other things and using Promise.all(). When I removed it from the array of promises and ran in its own separate promise, it ran successfully. I don't know why the AWS SDK's promise method is not compatible with most other promise related features of nodejs...


  2. Maybe it will help someone, I’ve got this error when tried to use promisify() on a send() function. It seems like function loses context or something. I promisified it manually with return new Promise(resolve => {})... and everything started to work as expected.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search