【问题标题】:Get Thing Shadow of Aws iot thing in lambda function在 lambda 函数中获取 Aws iot 事物的事物影子
【发布时间】:2016-10-01 16:13:32
【问题描述】:

我试图在 lambda 函数中获取 aws iot 资源的影子,但给定的代码在成功时给出空值而不是数据。请让我知道问题出在哪里以及我应该做哪些更改才能使其正常工作。提前致谢。

var AWS=require('aws-sdk');
var iotdata = new AWS.IotData({endpoint: 'XXXXXXXXX.iot.us-east-1.amazonaws.com'});
var params = {
thingName: 'thing_name' /* required */
};

exports.handler=function(event,context){
payload1=new Buffer(event.payload);
console.log(payload1); 
iotdata.getThingShadow(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response

  context.succeed(data);

});

};

【问题讨论】:

  • 如果您从 CLI 运行 aws iot list-things,输出是什么?

标签: node.js amazon-web-services aws-lambda aws-iot


【解决方案1】:

需要更改的地方很少。这是新代码:

getIotShadow: function (thingName) {
    config.IOT_BROKER_ENDPOINT = "xxxxxxxxx.iot.us-east-1.amazonaws.com"; // also called the REST API endpoint
    config.IOT_BROKER_REGION = "us-east-1"; // eu-west-1 corresponds to the Ireland Region.  Use us-east-1 for the N. Virginia region
    config.IOT_THING_NAME = thingName;
    AWS.config.region = config.IOT_BROKER_REGION;
    var iotData = new AWS.IotData({
        endpoint: config.IOT_BROKER_ENDPOINT
    });

    var paramsGet = {
        "thingName": config.IOT_THING_NAME /* required */
    };

    iotData.getThingShadow(paramsGet, function (err, data) {
        if (err) {
            console.log("Error : " + err, err.stack);
        } else {
            console.log(JSON.stringify(data));
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-03
    • 2016-07-02
    • 1970-01-01
    • 2020-08-05
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多