简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM