I have this error with aws-sdk library and I didn’t found the reason.

I have tried any possibilities for many days but without success and no clue of what’s happen It’s a Status code 400 but I have checked for many examples in web and everything is fine to me.

Here is the code

var AWS = require('aws-sdk');
AWS.config.update({ region: 'nyc3' });

var uuid = require('node-uuid');
var fs = require('fs');

// Create an S3 client
var s3 = new AWS.S3({
  apiVersion: '2006-03-01',
  secretAccessKey: '*****',
  accessKeyId: '*****',
  endpoint: 'https://nyc3.digitaloceanspaces.com',
  region: 'nyc3'
});

AWS.config.region = 'nyc3';

const fileName = 'hello_world.txt';

// Create a bucket and upload something into it
var bucketName = 'my-bucket';
var keyName = fileName;

fs.readFile(fileName, (err, data) => {
  if (err) throw err;
  var params = {
    ACL: 'private',
    Bucket: bucketName,
    Key: keyName,
    Body: JSON.stringify(data, null, 2),
    ContentLength: data.length
  };
  s3.putObject(params, function(err, data) {
    if (err) console.log(err);
    else
      console.log(
        'Successfully uploaded data to ' + bucketName + '/' + keyName
      );
  });

  // s3.upload(params, function(s3Err, data) {
  //   if (s3Err) console.log(s3Err);
  //   else console.log(`File uploaded successfully at ${data.Location}`);
  // });
});

You can see that I have tried with the putObject and upload methods and have the same error in both of them

{ InvalidArgument: null
    at Request.extractError (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/services/s3.js:816:35)
    at Request.callListeners (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
  message: null,
  code: 'InvalidArgument',
  region: null,
  time: 2020-02-28T03:20:24.289Z,
  requestId: 'tx00000000000016f648fab-005e5886f8-3359f-nyc3b',
  extendedRequestId: undefined,
  cfId: undefined,
  statusCode: 400,
  retryable: false,
  retryDelay: 38.29641987933954 }

I don’t have any more idea of what I can do to fix this. Any one can help?

1 comment
  • I’m having the same issue. Unfortunately the error message is not intelligible or actionable. I tried digging into the s3-adapter source code but there doesn’t appear to be anything wrong there. It’s actually an error coming from the digital ocean’s spaces api it seems which is unexpected.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

I had this error because of StorageClass: 'REDUCED_REDUNDANCY' in my upload options, removing it sorted the issue.

Submit an Answer