0

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?

3
  • Is the first sentence a typo? I don't think the AWS-sdk is capable of interacting with GCS. Commented Dec 29, 2021 at 22:00
  • @CollinD No, the project I'm currently working on used to work with AWS S3 but then migrated to GCS so we are using the Migration from AWS to GSC solutions for now. But other methods work just fine, it's just this kind of error that is really hard to degub. Commented Dec 30, 2021 at 0:46
  • That's mighty fancy, today I learned. Thanks for sharing! Commented Dec 30, 2021 at 1:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.