Class: AWS.Lambda

Identifier:
lambda
API Version:
2017-09-20
Defined in:
lambda.js

Overview

Constructs a service interface object. Each API operation is exposed as a function on service.

Constructor Summary collapse

Method Summary collapse

Constructor Details

new GG.Lambda() ⇒ Object

Constructs a service object. This object has one method for each API operation.

Examples:

Constructing a Lambda object

var lambda = new GG.Lambda();

Method Details

invoke(params = {}, callback) ⇒ AWS.Request

Invokes a specific Lambda function.

In Greengrass, version of the Lambda which you would like to invoke needs to be provided.

Service Reference:

Examples:

To invoke a Lambda function


/* This operation invokes a Lambda function */

 var params = {
  ClientContext: "MyApp", 
  FunctionName: "MyFunction", 
  InvocationType: "Event", 
  Payload: <json | binary>, 
  Qualifier: "1"
 };
 lambda.invoke(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
 });

Calling the invoke operation

var params = {
  FunctionName: 'STRING_VALUE', /* required */
  ClientContext: 'STRING_VALUE',
  InvocationType: Event | RequestResponse,
  Payload: <json | binary>,
  Qualifier: 'STRING_VALUE'
};
lambda.invoke(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

Parameters:

  • params (Object) (defaults to: {})
    • FunctionName — (String)

      The Lambda function name.

      You can specify Amazon Resource Name (ARN) of the function (for example, arn:aws:lambda:us-west-2:account-id:function:ThumbNail).

    • InvocationType — (String)

      By default, the Invoke API assumes RequestResponse invocation type. You can optionally request asynchronous execution by specifying Event as the InvocationType.

      Possible values include:
      • "Event"
      • "RequestResponse"
    • ClientContext — (String)

      Using the ClientContext you can pass client-specific information to the Lambda function you are invoking. You can then process the client information in your Lambda function as you choose through the context variable. For an example of a ClientContext JSON, see the main page or an example folder for an example.

      The ClientContext JSON must be base64-encoded.

    • Payload

      Payload that you want to provide to your Lambda function as input. Please refer to the main page or examples for proper formats.

    • Qualifier — (String)

      You can use this optional parameter to specify a Lambda function version if it was not included in the FunctionName field. If you specify a function version, the API uses the qualified function ARN to invoke a specific Lambda function.

      If you don't provide this parameter, then the API uses the FunctionName field only. If it does not have a version number of the target lambda, the call will fail.

Callback (callback):

  • function(err, data) { ... }

    Called when a response from the service is returned.

    Parameters:

    • err (Error)

      the error object returned from the request. Set to null if the request is successful.

    • data (Object)

      the de-serialized data returned from the request. Set to null if a request error occurs. The data object has the following properties:

      • StatusCode — (Integer)

        The HTTP status code will be in the 200 range for successful request. For the RequestResponse invocation type this status code will be 200. For the Event invocation type this status code will be 202.

      • FunctionError — (String)

        Indicates whether an error occurred while executing the Lambda function. If an error occurred this field will have one of two values; Handled or Unhandled. Handled errors are errors that are reported by the function while the Unhandled errors are those detected and reported by AWS Lambda. Unhandled errors include out of memory errors and function timeouts. For information about how to report an Handled error, see Programming Model.

      • Payload — (Buffer, Typed Array, Blob, String)

        It is the result returned by the Lambda function. This is present only if the invocation type is RequestResponse.

        In the event of a function error this field contains a message describing the error. For the Handled errors the Lambda function will report this message. For Unhandled errors AWS Lambda reports the message.