Node Upload file to S3 error InvalidArgument: null

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: '',
  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);
        '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?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

The error message is complete unhelpful garbage… here is a troubleshooting approach that worked for me:

  1. Try to remove the API version. Let it select latest automatically.
  2. Try to set sample Body manually; just a “sample text”, for instance.
  3. If the above doesn’t work, use the tutorial below to work backwards from first making sure you can list your buckets, then list all objects in your bucket, and then use their example of “putObject”. If that works, start to replace params one by one to see where you’re going wrong.

In MY case, the problem was that I was using ACL: “public”, and there’s no such thing… I had to do ACL: “public-read”

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