0

I'm replacing s3cmd usage with AWS JS SDK.

In s3cmd command there is an option to set a custom config file: s3cmd -c "/path/to/config". But I can't find how to use the same configuration file in "aws-sdk" (shared credentials file)?

My code looks like following:

let cnf_file = path.join(__dirname, "../config");
process.env.AWS_SHARED_CREDENTIALS_FILE = cnf_file;
const S3 = require('aws-sdk/clients/s3');
let s3 = new S3();
let params = {
//...
};
s3.putObject(params, (err, response) => {});

But I get errors:

message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',

message: 'Could not load credentials from any providers',

v.babak
  • 818
  • 11
  • 13

1 Answers1

0

I've found the problem was that s3cmd configuration file isn't compatible with aws-sdk because of different properties names for access key and secret key.

So I ended up with this line: this.s3 = new S3({ accessKeyId, secretAccessKey }); which made it working.

v.babak
  • 818
  • 11
  • 13