如何在AWS lambda函数上安装mqtt库

时间:2018-04-19 12:40:02

标签: aws-lambda

我想从 AWS lambda函数发布 mqtt 消息,我试过这个

`exports.handler = function(event, context) {
// TODO implement
context.done(null, 'Hello from Lambda');
const mqtt = require('mqtt');
const client = mqtt.connect('mqtt://broker.hivemq.com');


 var state = 'closed';

 client.on('connect', () => {
 console.log("connected to broker");
 // Inform controllers that garage is connected
 client.publish('garage/connected', 'true')
 })
 };

`

1 个答案:

答案 0 :(得分:1)

您需要使用node_modules目录和lambda的源文件创建一个zip文件。

e.g。

SELECT  FIXTURE.Fixture_ID, FIXTURE.Game_Date, TEAM.Team_Name,
        OPPONENT.Opponent_Team_Name, FIXTURE.Results, FIXTURE.Score,
        FIXTURE.Location
    FROM  FIXTURE
    WHERE  FIXTURE.Location='Home'
    JOIN  TEAM  ON FIXTURE.TM_ID = TEAM.Team_ID
    JOIN  OPPONENT  ON FIXTURE.OPP_ID = OPPONENT.Opponent_ID
    GROUP BY  Game_Date
    ORDER BY  Game_Date DESC;

您应该使用npm在本地安装软件包。

详细信息在Lambda文档here

中描述