Skip to main content

AWS Lambda

Latest version: 1.0.0

This library can be used to invoke Amazon Web Services (AWS) Lambda functions from your agent code. It depends upon the AWSRequestV4 library, which must be included too.

You can view the library’s source code on GitHub. Click here to see information on the available versions of this library.

To include this library in your project, add

#require "AWSLambda.agent.lib.nut:1.0.0"
#require "AWSRequestV4.class.nut:1.0.2"

at the top of your agent code

Class Methods

Constructor(region, accessKeyID, secretAccessKey)

The AWSLambda object constructor takes the following parameters:

Parameter Type Description
region String AWS region (eg. "us-east-1")
accessKeyID String IAM Access Key ID
secretAccessKey String IAM Secret Access Key

Example

#require "AWSLambda.agent.lib.nut:1.0.0"
#require "AWSRequestV4.class.nut:1.0.2"

const AWS_LAMBDA_REGION = "us-west-1";
const ACCESS_KEY_ID     = "<YOUR_ACCESS_KEY_ID>";
const SECRET_ACCESS_KEY = "<YOUR_SECRET_ACCESS_KEY>";

lambda <- AWSLambda(AWS_LAMBDA_REGION, ACCESS_KEY_ID, SECRET_ACCESS_KEY);

invoke(params[, callback])

This method invokes a lambda function. Please refer to the AWS Lambda documentation for more details.

The function takes the following parameters:

Parameter Type Description
params Table Table of parameters, see below
callback Function Callback function that takes one parameter: an httpresponse object

 
The params table can contain the following keys:

Parameter Type Required Default Value Description
functionName String Yes N/A Name of the Lambda function to be called
payload Serializable data Yes N/A Data that you want to provide to your Lambda
contentType String No "application/json" The payload content type

Example

local payload = { "message" : "Hello, world!" };
local params  = { "payload" : payload,
                  "functionName" : "MyLambdaFunction" };
lambda.invoke(params, function (result) {
    local payload = http.jsondecode(result.body);
    if ("Message" in payload) {
        server.log("Invocation error: " + payload.Message);
    } else if ("errorMessage" in payload) {
        server.log("Runtime error: " + payload.errorMessage);
    } else {
        server.log("[SUCCESS]: " + payload.result);
    }
}.bindenv(this));

Release History

The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.

Version Source Code Notes
1.0.0 GitHub Initial release

License

The AWSLambda library is licensed under the MIT License.