Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
How to debug InvalidArgument error on deleteObjects using aws-sdk for nodeJs

I'm currently using aws-sdk on version ^2.962.0 in a nodeJS application that I'm working ono to connect to a Google Cloud Storage bucket and delete files but I'm getting the "InvalidArgument: Invalid argument" error.

obs: the project I'm currently working on used to work with AWS S3 but migrated to GCS so we are using the Migration from AWS to GSC solutions for now. Other methods and libs work fine.

Here's part of the code where I'm using deleteObjects method:

import { S3 } from 'aws-sdk';  

const s3 = new S3({
  accessKeyId: process.env.S3_ACCESS_KEY,
  secretAccessKey: process.env.S3_SECRET,
  endpoint: process.env.S3_ENDPOINT,
  logger: console
}

const bucket = process.env.S3_BUCKET_FILES;
const folderPath = 'someFolder/';

try{
  const objectsKeys: Array<any> = [];
  const objectsList = await s3.listObjects( {
    Bucket: bucket,
    Delimiter: '/',
    Prefix: folderPath
  } ).promise();
    
  objectsList.Contents.forEach( ( file ) => {
    const objectKey = file.Key;

    if ( objectKey === folderPath ) {
      return;
    }
    objectsKeys.push( { Key: objectKey } );
  } );
    await s3.deleteObjects( { //<< There seems to be some error of argument
      Bucket: bucket,
      Delete: {
        Objects: objectsKeys
      }
    } ).promise();
}
catch(err){
console.log(err)
}

I have tried all sorts of configurations while passing the params to the s3.deleteObjects method but I can't work around the error:

//AWS logs and error
[AWS s3 200 0.378s 0 retries] listObjects({ Bucket: 'myBucket-files', Delimiter: '/', Prefix: 'testFolder/' })
[AWS s3 400 0.216s 0 retries] deleteObjects({
  Bucket: 'myBucket-files',
  Delete: {
    Objects: [
      { Key: 'testFolder/e96ab708dab513e6c00ff21afbf02773' },
      [length]: 1
    ]
  }
})

InvalidArgument: Invalid argument.
    at Request.extractError (C:\...) { // all the path until the error at the package folder
  code: 'InvalidArgument',
  region: null,
  time: 2021-12-29T20:34:04.924Z,
  requestId: null,
  extendedRequestId: undefined,
  cfId: undefined,
  statusCode: 400,
  retryable: false,
  retryDelay: 94.12732588991155
}

Does someone know any way to extract the exact argument in such cases or to get a log of expected parameters and delivered so that one could compare it? I've managed to turn on the logger config on the S3 client instance as the documentation suggests but it doesn't seem to be more precise on the debugging. Can anyone spot the error?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems that Google Cloud Storage does not support some of aws sdk functions, including deleteObjects. This answer discusses a bit more about this issue. Still, I did not find any other "easy" way to debug this InvalidArgument type of error.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!