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

368
Visualizações
How to invoke a lambda function in aws-sdk v3

How can I invoke a lambda function using Javascript (TypeScript) aws-sdk v3?

I use the following code which does not seems to work:

// the payload (input) to the "my-lambda-func" is a JSON as follows:
const input = {
    name: 'fake-name',
    serial: 'fake-serial',
    userId: 'fake-user-id'
};

// Payload of InvokeCommandInput is of type Uint8Array
const params: InvokeCommandInput = {
    FunctionName: 'my-lambda-func-name',
    InvocationType: 'RequestResponse',
    LogType: 'Tail',
    Payload: input as unknown as Uint8Array, // <---- payload is of type Uint8Array
  };
  
  console.log('params: ', params); // <---- so far so good.
  const result = await lambda.invoke(params);
  console.log('result: ', result); // <---- it never gets to this line for some reason.

I see this error message in CloudWatch, not sure if it is relevant to my issue thought:

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object

Question:

Is the above code to invoke a lambda function correct? or are there any better ways?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like your call to lambda.invoke() is throwing a TypeError because the payload that you are passing to it is an object when it needs to be a Uint8Array buffer.

You can modify your code as follows to pass the payload:

// import { fromUtf8 } from "@aws-sdk/util-utf8-node";

const { fromUtf8 } = require("@aws-sdk/util-utf8-node");

// the payload (input) to the "my-lambda-func" is a JSON as follows:
const input = {
  name: 'fake-name',
  serial: 'fake-serial',
  userId: 'fake-user-id'
};

// Payload of InvokeCommandInput is of type Uint8Array
const params: InvokeCommandInput = {
  FunctionName: 'my-lambda-func-name',
  InvocationType: 'RequestResponse',
  LogType: 'Tail',
  Payload: fromUtf8(JSON.stringify(input)),
};
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