Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 1.78 KB

README.md

File metadata and controls

44 lines (34 loc) · 1.78 KB

aws-mqtt-gate

AWS Lambda function creating a getaway from HTTP(s) to MQTT

Initially aimed to route messages from Telegram messenger to a Telegram bot via the AWS IoT broker.
May be used as a "general purpose" getway from HTTP(s) to MQTT.

Use cases

  • Telegram Bot running on a cheep OpenWRT router with poor GSM connection
  • Server running behind NAT with slow Internet connection without real IP that listens to commands via MQTT

How it works

  • API URL exposed via AWS API shall be registered as the Telegram "Webbhook" for your bot.
  • On receiving a message, the Telegram sends the requests to the "webhook" that AWS routes to this Lambda function.
  • This function:
    - checks identity (see "authorization")
    - takes the whole content of the request body as the payload for the MQTT message
    - publishes the payload to the AWS IoT broker under the topic specified in config.js

Authorization of requests

In addition to AWS built-in authorization options (may be difficult to use with external services) this script supports

  • authorization by IP-address of the requesting host
  • HMAC code in the request params or body
  • User/password in the URL
    (refer to "authRules" section in config.js)

How to use

  1. Prerequisites:
    - sign up to AWS Lambda, AWS API, AWS IoT
    - install node.js and npm (claudia.js and node-lambda.js may be helpful)
    - clone the repository
  2. Setup HTTP(s) API, register a "thing" with AWS IoT (create and download certificates for the "thing")
  3. Update config.js with your settings, upload certificate (if needed)
  4. Deploy to AWS Lambda ('npm run-script deploy' may be helpful)
  5. Test with 'npm run-script test-aws'

Tests

npm test

Licence

ISC
vadim.konstantinov@gmail.com