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

252
Visualizações
'Credential is missing' Error On Instantiating S3 Class Using AWS-SDK JS V3

I am getting en error when creating S3 client from class S3 in newer v3 of aws-sdk javascript.

I add aws config parameters including credentials obtained from aws sts when user gets authenticated (assuming a role with permission to call getObject) at service-level (when instantiating S3 class) along with other parameters. See my code below:

const { S3, ... } = require("@aws-sdk/client-s3");

someFunc();
function someFunc(authUserCredentials) {
 ...
 try {

   const { AccessKeyid, SecretKey, SessionToken } = authUserCredentials;
   const s3Client = new S3({
                      signatureVersion: 'v4',
                      accessKeyId: AccessKeyId,
                      secretAccessKey: SecretKey,
                      sessionToken: SessionToken,
                      region: 'us-east-1',
   });

   console.log(s3Client.config);
   ...

 }catch(e) {
     console.error(e);
 }
}

I checked the class S3 code in aws-sdk-js-v3 repo, and there doesn't seem to be no 'Credential' constructor config argument required. Am I doing something wrong?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Just to clarify Chris Williams's answer combined with @Waleed93's second comment, what used to work with the AWS Javascript SDK v2 is:

import S3 from 'aws-sdk/clients/s3';

const AccessKeyId = xxxxx,
      SecretKey = yyyyyyyy,
      SessionToken = zzzzzzzzzz;

const s3Client = new S3({
    apiVersion: '2006-03-01',
    region: 'us-east-1',
    accessKeyId: AccessKeyId,
    secretAccessKey: SecretKey,
    sessionToken: SessionToken
});

For SDK v3, the constructor no longer accepts individual credential parameters but does take a "credentials" object as a parameter. What works is:

const { S3 } = require('@aws-sdk/client-s3');

const AccessKeyId = xxxxx,
      SecretKey = yyyyyyyy,
      SessionToken = zzzzzzzzzz;

const creds = {
    accessKeyId: AccessKeyId,
    secretAccessKey: SecretKey,
    sessionToken: SessionToken
};

const s3Client = new S3({
    apiVersion: '2006-03-01',
    region: 'us-east-1',
    credentials: creds
});

This change is nowhere to be found in the AWS SDK documentation, class reference, or Developer Guide for SDK Version 3. Thank you to Chris and @Waleed93 for figuring it out.

over 4 years ago · Santiago Trujillo Relatório

0

According to the documentation for the constructor these arguments are valid.

There is still an argument name for the Credential object with the name credentials. If you instantiate a AWS.Credentials object you can pass this into that argument.

over 4 years ago · Santiago Trujillo Relatório

0

The value of credentials should be an object containing your credentials passed into the config as below:

import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3'

const CREDENTIAL = {
  accessKeyId: 'accesKeyIdString',
  secretAccessKey: 'secretAccessKeyIdString',
};

const REGION: 'aws region';
const s3Client = new S3Client({region: REGION, credentials: CREDENTIAL});
over 4 years ago · Santiago Trujillo 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