Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda