AWS Alexa Smart Home Skill: load sample code and test Lambda – 6

Spread the love

In this article we upload the Lambda sample code, it must first be packaged and then uploaded to AWS as a function code.

Amazon AWS Smart Home Skill deploy code and test lambda
Amazon AWS Smart Home Skill deploy code and test lambda

Package the Sample Code

  1. In your working directory, browse to the skill-sample-nodejs-smarthome-switch/lambda/smarthome directory.
  2. In that directory and from the command-line, run the following command to install the dependencies: npm install.
  3. Zip the contents of the functions\lambda\skill-esp8266-nodejs-smarthome-switch directory into a file named package.zip and save it to the alexa-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 script createLambdaPackage.bat.

Upload the Sample Code

Alexa Skill Smarthome: Lambda upload from zip file
Alexa Skill Smarthome: Lambda upload from zip file
  1. 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.
  2. In the Load from dropdown, select File .zip.
  3. Click the Upload button and browser to the alexa-skill-manage-relay directory or where you zipped the packaged code.
  4. Select the package.zip file to upload as the lambda function code.
  5. 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

Alexa Skill Smarthome: Lambda test event discovery
Alexa Skill Smarthome: Lambda test event discovery
  1. 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.
  2. In the dialog that opens, leave Create new test event selected and leave the default template.
  3. For the Event name enter: directiveDiscovery.
  4. 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>"
      }
    }
  }
}
  1. Click Create.

Thanks

  1. AWS Alexa Smart Home Skill: introduction and startup
  2. AWS Alexa Smart Home Skill: create the skill manage the security
  3. AWS Alexa Smart Home Skill: create lambda and manage security
  4. AWS Alexa Smart Home Skill: configure lambda for the skill
  5. AWS Alexa Smart Home Skill: setup the DynamoDB database
  6. AWS Alexa Smart Home Skill: load sample code and test Lambda
  7. AWS Alexa Smart Home Skill: test your skill in dev and manage log

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *