Menu
Open source

LambdaClient.invoke(name, payload, [options])

LambdaClient.invoke invokes an AWS Lambda function.

Parameters

ParameterTypeDescription
namestringName of the function to invoke.
payloadstringPayload to send to the function being invoked.
optionsInvocationOptionsAdditional options to customize the invocation.

InvocationOptions

InvocationOptions is an object used to customize the invocation of a Lambda function. It has the following properties:

PropertyTypeDescription
invocationTypestring (optional)Specifies the invocation type (synchronous or asynchronous). Possible values are: RequestResponse, which invokes the function synchronously, Event, which invokes the function asynchronously, and DryRun which validates the parameter values and verifies that the user or role has permission to invoke the function. Default is RequestResponse.
logTypestring (optional)Specifies the type of log to include in the response. Set to Tail to include the execution log in the response. Applies to synchronously invoked functions only. Default is None.
clientContextstring (optional)Client context to pass to the function. Can be made up of up to 3,583 bytes of base64-encoded data. Default is null.
qualifierstring (optional)Version or alias of the function to invoke.

Returns

TypeDescription
Promise<InvocationResponse>A promise that fulfills when the object has been deleted from S3.

InvocationResponse

InvocationResponse is an object that represents the response of an invocation. It has the following properties:

PropertyTypeDescription
statusCodenumberStatus code of the invocation.
executedVersionstring (optional)The version of the function that executed.
logResultstring (optional)Log result of the invocation.
payloadstring (optional)Payload returned by the function.

Example

JavaScript
import {
  AWSConfig,
  LambdaClient,
} from 'https://jslib.k6.io/aws/0.12.3/lambda.js';
import { check } from 'k6';

const awsConfig = new AWSConfig({
  region: __ENV.AWS_REGION,
  accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
  secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
  sessionToken: __ENV.AWS_SESSION_TOKEN,
});

const lambdaClient = new LambdaClient(awsConfig);

export default async function () {
  const response = await lambdaClient.invoke('add-numbers', JSON.stringify({ x: 1, y: 2 }));

  check(response, {
    'status is 200': (r) => r.statusCode === 200,
    'payload is 3': (r) => r.payload === 3,
  });
}