Book Image

Learning AWS IoT

By : Agus Kurniawan
Book Image

Learning AWS IoT

By: Agus Kurniawan

Overview of this book

The Internet of Things market increased a lot in the past few years and IoT development and its adoption have showed an upward trend. Analysis and predictions say that Enterprise IoT platforms are the future of IoT. AWS IoT is currently leading the market with its wide range of device support SDKs and versatile management console. This book initially introduces you to the IoT platforms, and how it makes our IoT development easy. It then covers the complete AWS IoT Suite and how it can be used to develop secure communication between internet-connected things such as sensors, actuators, embedded devices, smart applications, and so on. The book also covers the various modules of AWS: AWS Greengrass, AWS device SDKs, AWS IoT Platform, AWS Button, AWS Management consoles, AWS-related CLI, and API references, all with practical use cases. Near the end, the book supplies security-related best practices to make bi-directional communication more secure. When you've finished this book, you'll be up-and-running with the AWS IoT Suite, and building IoT projects.
Table of Contents (14 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Accessing AWS Lambda from IoT devices


All API SDK for accessing AWS IoT, including AWS Greengrass, can be obtained on the software menu from AWS IoT Management Console. You can install it based on your device and runtime platforms.

In this section, I will show you how to invoke Lambda from AWS Greengrass Core. For testing, I used the Node.js application. You should install the aws-sdk library for Node.js. You also need to access the key ID and secret access key from the AWS IAM.

Please write the following complete program:

var AWS = require('aws-sdk');
AWS.config.update({region:'<region>'});

var accessKeyId = '<accessKeyId>'
var secretAccessKey = '<secretAccessKey>';
AWS.config.update({accessKeyId: accessKeyId, secretAccessKey: secretAccessKey});

var lambda = new AWS.Lambda();
var params = {
 FunctionName: '<lambda-function-arn>', 
 Payload: '{"msg": "this is testing"}'
};
lambda.invoke(params, function(err, data) {
 if (err) console.log(err, err.stack); 
 else console...