node.js - AWS Lambda putting item from MQTT request -
i try put mqtt request content dynamodb lambda function script :
var aws = require("aws-sdk"); var dynamodb = new aws.dynamodb(); exports.handler = function index(e,ctx,callback){ //var msg = json.stringify(ctx); var msg = e.name; var params = { tablename:"mytable", item:{ val: {s: msg}, valid: { s:"id"} } }; dynamodb.putitem(params,callback); callback(null,"putting item marcel !!"); }
i have create/set thing/rule/policy , script work but, have undefined value, try mqtt content store db. test post new topic sns, didn't use correct format have post message (raw):
{"val":"value"} val:"value" "val":value
i find way solve :
var aws = require("aws-sdk"); var dynamodb = new aws.dynamodb(); exports.handler = function index(e,ctx,callback){ // new block const record = e.records[0].sns.message; var msgjson = json.parse(record); var msg = msgjson.key1; var msg2 = msgjson.key2; var string_to_send = json.stringify(msg)+"-"+json.stringify(msg2); // var clean_string = string_to_send.split('"').join(''); var params = { tablename:"mytable", item:{ val: {s: clean_string}, valid: {s: "id"} } }; dynamodb.putitem(params,callback); callback(null,"putting item marcel !!"); }
for test need use sns publish in topic :
{"key1": {"thevalue1"},"key2": {"thevalue2"}}
or lambda actions -> configure test event -> sns, in message field put :
{\"key1\": \"val\",\"key2\": \"valid\"}
this work have useless " use split delete it.
Comments
Post a Comment