I am trying to upload files to my S3 bucket from my Node.js app, so I am following some very simple tutorials like this one.
The code is pretty straightforward :
const AWS = require("aws-sdk"); // fresh install, version : ^2.697.0
AWS.config.update({ // Credentials are OK
accessKeyId: process.env.s3_accessKeyId,
secretAccessKey: process.env.s3_secretAccessKey,
region: 'eu-central-1'
});
const s3 = new AWS.S3();
let params = {
// (some upload params, file name, bucket name etc)
};
s3.upload(params); // <-- crash with error: "s3.upload is not a function"
I had a look at the official AWS documentation and s3.upload()
seems to be a thing. I have no idea why I get an error.
If I console.log(s3.upload)
I get undefined
.
Node.js v13.11.0.
EDIT
I ended up using s3.putObject()
which does pretty much the same thing as s3.upload()
, and works, while the latter is still inexplicably undefined...
console.log(`typeof s3.upload = `);
console.log(typeof s3.upload); // undefined?? WHY
console.log(`typeof s3.putObject = `);
console.log(typeof s3.putObject); // function, and works
upload
? – Lucinalucindaconsole.log(s3.copyObject)
gives[ 'length', 'name', 'arguments', 'caller', 'prototype' ]
so it is defined. Same thing forconsole.log(s3.createBucket)
, it's not undefined. Looks like the problem is specific toupload
indeed – Cantilena