javascript: assign to a variable the content of a webpage (AWS)

Hi, I’m trying to assign the body of a webpage to a variable. I’m able to write it’s content on the console but not to assign it to the variable (UD2 in this case. I need to write the body on the shadow but I’m able to report it just on cloudwatch logs). I report my code, it’s a lambda function, and I’m working with iot shadow and cloudwatch. Is there anyone that can help me? Thanks, Eleonora

<pre>

 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://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&APPID=123”;

https.get(encodeURI(querystring), function(res) {
console.log("Got response: " + res.statusCode);
res.setEncoding(‘utf8’);
res.on(‘data’, function(d) {

console.log('Body: ’ + d);
return d;
});
context.succeed(res.statusCode);
// console.log(res);
return res;

}).on(‘error’, function(e) {
console.log("Got error: " + e.message);
context.fail(e.message);
});

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);

var desiredUD2;
if(currentUD1 == 1) {

desiredUD2 = https.get.d;
console.log(desiredUD2);

}
else {

desiredUD2=https.get.d;
console.log(desiredUD2);

}

var desiredState = {
state: {
desired: {

UD2:https.get.d
},
reported: {

UD2:https.get.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);
}
});
};

</pre>

Hi @eleonora1984,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our community organized so users can more easily find information.

As you’ll notice, your topic is now here in the Project Development Help and Advice board. No action is needed on your part; you can continue the conversation as normal here.

Cheers!