Sabo Boz
Sabo Boz

Reputation: 2575

newer version of lambda.invoke from aws-sdk (javascript)

I wish to execute code that runs like the lambda.invoke function from https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html. e.g.

import AWS from 'aws-sdk'
var lambda = new AWS.Lambda()
var params = {
FunctionName: func,
InvocationType: "Event",
Payload: obj
}
await lambda.invoke(params).promise()

However, this is from an older version (v2) and I wish to achieve the same result using the javascript aws-sdk v3. I am looking at the documentation at https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/index.html, but I can't find out which function will let me achieve the same result. Would anyone know how to achieve the same invocation of the lambda in a 'fire and forget' manner?

Upvotes: 0

Views: 2122

Answers (1)

Jens
Jens

Reputation: 21530

The following snippet is taken from the official documentation and extended with a example for the required input. Please be sure to study the documentation for further information.

import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda"; // ES Modules import

const client = new LambdaClient();

// see: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/interfaces/invokecommandinput.html
const input = {
  FunctionName: "",
  InvocationType: "",
  LogType: "",
  Payload: "",
  Qualifier: ""
}

const command = new InvokeCommand(input);
const response = await client.send(command);

Documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/classes/invokecommand.html

Upvotes: 4

Related Questions