ApplicationExperienceEdge 1.0.0

AWS Lambda Node

The AWS Lambda Node allows a workflow to run an AWS Lambda function and optionally store the returned value from the function in the payload.

AWS Lambda Node

Node Properties

There are four sections of node properties for the AWS Lambda node: AWS Config, Lambda Config, Output, and Error.

AWS Configuration

AWS Lambda Node Credentials

There are three required fields in the AWS Config section:

  • AWS Access Key ID Template
  • AWS Secret Access Key Template
  • AWS Region Template

Losant recommends that you create an AWS Key/Secret pair specifically for use for our workflow nodes - one that only has access to your AWS Lambda functions. All three fields can take string templates, and so can pull values from the current payload. Most users store these values in their workflow globals.

In the example above, the node is configured to pull the AWS Access Key from globals.awsKey, the AWS Secret from globals.awsSecret, and sets the region to us-west-2.

Lambda Configuration

AWS Lambda Node Config

In this section the Lambda Function and Data Method are selected. The function to call can take a string template, so the value can be pulled off the payload - but in the example above, the function is hard-coded to userNumberLookup.

There are three options for Data Method:

  • Workflow Payload: with this option, the entire current workflow payload is sent as the data to the lambda call.
  • Payload Path: with this option, you must provide a payload path, and the value at that path on the current payload is sent as the data to the lambda call.
  • JSON Template: with this option, you must provide a JSON template, and the result of that template is sent as the data to the lambda call.

In the example above, Workflow Payload is selected, so the entire current payload will be handed to the userNumberLookup call.

Output Configuration

AWS Lambda Node Output

If the Lambda function that is being called returns a result, it can optionally be stored for later use in the workflow. In the example above, the result will be stored at the payload path data.phoneNumber on the current payload.

Error Configuration

This section determines how errors are handled when the node is run. There are two options:

  • Error the workflow: Halt the workflow at this node, preventing further execution.
  • Store AWS Lambda error at payload path: Configure a payload path at which to store the error.

Note: For edge workflows, this option is only available on edge version 1.18.1 or higher. On older versions, the workflow will always halt on errors.

Node Example

Here is an example payload after the above AWS Lambda Node has been run and received information back from the useNumberLookup function:

{
  "time": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
  "data": {
    "current": 10,
    "on": true,
    "phoneNumber": {
      "LogResult": "AWS_LOGGING_INFO_WOULD_BE_HERE",
      "Payload": { "phoneNumber": "212 867-5309" },
      "StatusCode": 200,
    }
  },
  "globals": {
    "awsKey": "AWS_KEY_WOULD_BE_HERE",
    "awsSecret": "AWS_SECRET_WOULD_BE_HERE"
  },
  "applicationId": "568beedeb436ab01007be53d",
  "applicationName": "Embree",
  "triggerId": "56c8967bb8df0f0100d629120",
  "triggerType": "deviceId",
  "deviceTags": {
    "floor": ["2"],
    "location": ["warehouse1"]
  },
  "deviceName": "My Factory Device",
  "flowId": "56c74add04d0b50100043381",
  "flowName": "Power Usage Alert"
}

Node Errors

In the case that the AWS Lambda function fails, there are two possible options. You can either error the workflow, or you can store the error at a path on the payload.

Below is an example of an error stored on the payload when the configured AWS credentials are invalid and the error is stored on the payload path “working.lambdaError”:

{
  "working": {
    "lambdaError": {
      "message": "The security token included in the request is invalid.",
      "type": "AWSLambda"
    },
    ...
  }
}