This is a NodeJS application meant to be run in an AWS Lambda function in order to issue MQTT messages to an IoT device in response to an Alexa voice command.
There are quite a few prerequisites to this. Starting with hardware:
- Amazon Echo, Echo Dot, or some other Alexa device
- ESP8266-based microcontroller
- Internet browser
- AWS account
There is a wealth of information out there on how to get started with the Alexa Skills Kit as well as how to use it with Lambda. Here's a rough list of steps to get started:
-
Create an AWS IAM user and attach the AWSIoTFullAccess policy (or some subset of it)
-
Create an access key and note your ID and secret
-
Create an AWS IoT "Thing" that represents your device; this will also act as the MQTT broker
-
Create a
certs/
folder in this repository and save the generated certificates to it -
Create a security policy for the Thing that gives it permissions to run AWS IoT API calls
-
Connect to your thing via MQTT and the AWS Arduino SDK (see my ESP8266 code for an example; you will need the AWS access key you created earlier)
-
Create an AWS Lambda function that will be our handler for Alexa voice commands
-
Log into https://developer.amazon.com and go to the Alexa tab
-
Select Alexa Skills Kit and configure a new skill
-
Under "Configuration", choose "AWS Lambda ARN" and supply the ARN of your Lambda skill
-
(Optional) Configure Account Linking for user info to be supplied to Alexa using your IAM ID and secret from earlier
-
Back in your Lambda function, set it up for this repo's code:
Runtime: Node.js 6.10 Handler: index.handler Role: Create a new role (if you don't have one) or Choose an existing role Existing role (if you have one): Your existing role Description: A description of this function
-
If you haven't configured a new role, create a new one and attach the AWSLambdaBasicExecutionRole policy to it
-
Add or verify that the Alexa Skills Kit is in the triggers
-
Add the certs created
-
Zip the contents of this repository (not the folder itself); the
build.sh
script in this repository will create a zip file in the directory above this one -
Under the "Code" tab, choose "Upload a .ZIP file" and upload the zip you just created
-
Test by either issuing a voice command like "Alexa, tell trigger_name "Hello world" or by testing via the Alexa Skills Kit or Lambda test interfaces
You should see this response following a successful trigger:
{
"version": "1.0",
"response": {
"shouldEndSession": true,
"outputSpeech": {
"type": "SSML",
"ssml": "<speak> Hello world! </speak>"
}
},
"sessionAttributes": {}
}
Or you will hear Alexa respond "Hello world!".
As mentioned, there is a wealth of reading available on configuring this chain. Here are some links I've found useful:
- joanaz/MirrorMirrorOnTheWallSkill - This guy goes right at the top for resolving how to send an IoT message as well as respond via voice
- Using Alexa Skills Kit and AWS IoT to Voice Control Connected Devices
- Alexa Account Linking: 5 Steps to Seamlessly Link Your Alexa Skill with Login with Amazon
- Arduino Using AWS IoT Service - For an Ameba microcontroller, but the IoT setup steps are the same
- Create an AWS Lambda Function for a Custom Skill
- aws/aws-iot-device-sdk-js
- odelot/aws-mqtt-websockets - Bit of a pain to set up but works flawlessly
- alexa/alexa-skills-kit-sdk-for-nodejs