Lambda analytics

Serverless Lambda functions are the easiest and most customizable form of analytics. Lambda analytics allow you to process data immediately, with powerful support for Python, Node.js, GO, C#, and Java. The easiest way to configure a Lambda function is through the AWS console as follows:

  1. From the AWS console, we have to search for Lambda and click on the Create function button
  1. Select the Author from scratch section and, for the name field, enter my_iiot_lambda_threshold. From the role template, we can define our role name as my_iiot_lambda_threshold_role:

Creating a Lambda function

After clicking on the Create function button, AWS will show a page similar to the following screenshot:

Triggering the Lambda function
  1. We can now create a custom IoT rule, named my_iiot_lambda_threshold_rule, that will be projected into the IoT Core act. As mentioned previously, the source is as follows:
SELECT * FROM 'signals/#'

Triggering the Lambda function
  1. Click on the Save button.
  1. Finally, we can write our function. Click on the my_iiot_lambda_threshold box and configure the entry for index.js as follows:

Coding the Lambda function
  1. Enter the following code into the index.js field:
exports.handler = (event, context, callback) => {
console.log(event);
if (event.temperature>20) console.log("Alert")
callback(null, 'Hello from Lambda');
};
  1. Click on the Save button.
  1. Now, it's time to test our function. From the command console, enter the following command:
$ node iiot-book-device.js

Let's take a look at the results in CloudWatch:

CloudWatch's log of the Lambda function
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset