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
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...