AWS Alexa Smart Home Skill: load sample code and test Lambda – 6
In this article we upload the Lambda sample code, it must first be packaged and then uploaded to AWS as a function code.
Package the Sample Code
- In your working directory, browse to the skill-sample-nodejs-smarthome-switch/lambda/smarthome directory.
- In that directory and from the command-line, run the following command to install the dependencies:
npm install
. - Zip the contents of the
functions\lambda\
directory into a file namedskill-esp8266-nodejs-smarthome-switch
package.zip
and save it to thealexa-skill-manage-relay
folder. Make sure that the index.js file, alexa/ folder, and node_modules/ folder are at the root of the zip file. Do not include the full path structure. If you have Java installed you can use the scriptcreateLambdaPackage.bat
.
Upload the Sample Code
- Navigate to
https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions/lambda-skill-esp8266-nodejs-smarthome-switch/latest?tab=code (North America)
https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/lambda-skill-esp8266-nodejs-smarthome-switch/latest?tab=code (Europe)
and locate the Code origin section. - In the Load from dropdown, select File .zip.
- Click the Upload button and browser to the
alexa-skill-manage-relay
directory or where you zipped the packaged code. - Select the
package.zip
file to upload as the lambda function code. - Click Save at the top right of the page. If successful, the environment of the Function code section will update replacing the previous contents.
Test the Lambda Function
After the sample code is uploaded to the Lambda function, you can test that it is properly working via the test events functionality of the AWS Lambda console. This is done by creating a Test Event that contains a sample directive message that the function code should handle and respond to.
Create a Discovery Test Event
- On the function page for skill-sample-nodejs-smarthome-switch, select the Select a test event.. dropdown from the top menu of the function and click Configure test events.
- In the dialog that opens, leave Create new test event selected and leave the default template.
- For the Event name enter:
directiveDiscovery
. - Copy and paste this contents, into the text field at the bottom of the dialog replacing its contents.
{
"directive": {
"header": {
"namespace": "Alexa.Discovery",
"name": "Discover",
"messageId": "<message id>",
"payloadVersion": "3"
},
"payload": {
"scope": {
"type": "BearerToken",
"token": "<an OAuth2 bearer token>"
}
}
}
}
- Click Create.
Thanks
- AWS Alexa Smart Home Skill: introduction and startup
- AWS Alexa Smart Home Skill: create the skill manage the security
- AWS Alexa Smart Home Skill: create lambda and manage security
- AWS Alexa Smart Home Skill: configure lambda for the skill
- AWS Alexa Smart Home Skill: setup the DynamoDB database
- AWS Alexa Smart Home Skill: load sample code and test Lambda
- AWS Alexa Smart Home Skill: test your skill in dev and manage log