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.
- 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
- 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 inconfig.js
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 inconfig.js
)
- 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 - Setup HTTP(s) API, register a "thing" with AWS IoT (create and download certificates for the "thing")
- Update config.js with your settings, upload certificate (if needed)
- Deploy to AWS Lambda (
'npm run-script deploy'
may be helpful) - Test with
'npm run-script test-aws'
npm test