Skip to Content
Learning AWS IoT
book

Learning AWS IoT

by Agus Kurniawan
January 2018
Intermediate to advanced
278 pages
5h 13m
English
Packt Publishing
Content preview from Learning AWS IoT

Building a Lambda program

We will build a Lambda function to filter an AWS IoT Button message. This message is parsed on an event  from the handler function. To store a message into AWS DynamoDB, we use the putItem() function from the DynamoDB object with the passing JSON message.

The following is the complete program for the AWS Lambda function:

var AWS = require('aws-sdk');var ddb = new AWS.DynamoDB();exports.handler = (event, context, callback) => {  var params = { TableName: 'aws-iot-button-db', Item: { 'msg-id': {S:new Date().getTime().toString()}, 'CLICKED' : {S:event.clickType}, 'BUTTON_ID' : {S:event.serialNumber}, } };  // Call DynamoDB to add the item to the table ddb.putItem(params, function(err, data) { if (err) { callback(err, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn AWS Serverless Computing

Learn AWS Serverless Computing

Scott Patterson

Publisher Resources

ISBN: 9781788396110Supplemental Content