Hi, I’m trying to write on aws shadow the content of a web page calling it via url using the api service. I succeed in writing on cloudwatch logs but not on shadow. In particular, I should write assign to UD2 the page content. Is there anyone that can help me? Thanks, Eleonora
console.log('Loading function');
var aws = require('aws-sdk');
var endpoint = '';
var thingName = '';
exports.handler = function(event, context) {
var https = require("https");
var querystring = "";
https.get(encodeURI(querystring), function(res) {
console.log("Got response: " + res.statusCode);
res.setEncoding('utf8');
res.on('data', function(d) {
//testtest = d;
console.log('Body: ' + d);
return d;
});
context.succeed(res.statusCode);
//console.log("res:" + res);
return res;
}).on('error', function(e) {
console.log("Got error: " + e.message);
context.fail(e.message);
});
//console.log("STATO: ",stato);
var iotdata = new aws.IotData( { endpoint: endpoint } );
var params = { thingName: thingName };
iotdata.getThingShadow(params, function (err, data) {
if (!err) {
var payload = JSON.parse(data.payload);
var currentUD1 = payload.state.desired.UD1;
var currentUD2 = payload.state.desired.UD2;
console.log("Current state : " + currentUD2);
// console.log("body: " +body);
var desiredUD2;
if(currentUD1 == 1) {
desiredUD2 = https.get.res.on.d;
console.log(desiredUD2);
}
else {
desiredUD2=https.get.res.on.d;
console.log(desiredUD2);
}
var desiredState = {
state: {
desired: {
UD2:https.get.ren.on.d
},
reported: {
UD2:https.get.res.on.d
}
}
};
var params = {
thingName: thingName,
payload: JSON.stringify(desiredState)
};
iotdata.updateThingShadow(params, function (err, data) {
if (!err) {
context.succeed();
} else {
context.fail(err);
}
});
} else {
context.fail(err);
}
});
};