January 2018
Intermediate to advanced
278 pages
5h 13m
English
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, ...