Skip to content

henrythasler/alexa-skill-tutorial

Repository files navigation

alexa-skill-tutorial

An AWS self-hosted demo skill for Amazon Alexa written in Typescript.

Main Goals

  • Develop an Alexa Skill with Typescript.
  • Self-host the skill-backend on AWS using Lambda as endpoint.
  • Automate the workflow as much as possible.
  • Implement tests and use additional tools to improve code quality.
  • Describe the workflow in as much detail as needed for future reference.

Prerequisites

To set up the whole environment you will need:

This tutorial assumes that you have all this set up and ready to use.

AWS Credentials for terraform

  • In AWS Console: go to IAM, create a new user and create an access key for that user
  • Make sure this terraform user has the required permissions to execute the instructions during terraform apply.
  • On your local machine: run aws configure and enter the access keys incl. secret key as prompted.

Terraform Initialization

  • in infrastructure/state.tf: change the values according to your setup to use another (remote) backend or remove this file if you want to keep the terraform state locally.
  • in infrastructure/variables.tf: change the region if needed. Please note, that no all regions can host Alexa Lambda functions. Refer to Select the optimal region for your AWS Lambda function for details.
  • in folder ./infrastructure: run terraform init to set up the required modules.

Create a new Alexa skill

  1. Log in to your Alexa Developer Console

  2. Create a new Skill

  3. Enter a name and select a language. Make sure to set Model to Custom and Host to Provision your own and press Create Skill.

  4. When promted for a template, choose Start from Scratch.

  5. The new skill will then be created within a few seconds. After completion, the skill-dashboard is shown. There should be some green checkmarks when everything went well.

  6. Go to Invocation and choose a Skill Invocation Name. Press Save Model and Build Model when done.

  7. Go to the Endpoint page. Copy the Skill ID to infrastructure/variables.tf (variable skill_id). Ignore the other input fields for now.

Deploy Lambda Function

  1. Open a terminal and change into the infrastructure folder. Execute terraform apply to set up all the components on AWS.
  2. Open up your AWS console (the web-interface...) in a new browser tab as we will need both consoles (Alexa Developer and AWS) simultaneously. Go to the Lambda Service and check that the lambda-function was set up correctly.
  3. Open up the details page and copy the ARN shown in the top right corner.
  4. Go back to the Endpoint page in your Alexa Developer Console and paste the Lambda-ARN into the Default Region field. Do not forget to Save Endpoints!

Testing

  1. Switch (again...) to the Lambda details page and select the Test button to create a new test event.

  2. Choose the alexa-skill-kit-start-session event template, enter an event name and press create.

  3. Press Test again with the previously created test event selected. You should now be able to see a successful execution of the lambda-function.

  4. Now switch back to the Test page in your Alexa Developer Console and change Skill testing is enabled in to Development. Enabling microphone access is optional.

  5. Speak (while pressing the microphone button) or type the skill invocation: open my tutorial. If everything went well, you can hear the responses that were defined in the RequestHandlers (src/tutorial-skill.ts). The request and response data (JSON) is also shown to the right and can be used for debugging purposes.

  6. Back to the AWS Lambda Console: Switch to the monitoring tab and check that the endpoint was called successful. For a detailled analysis (error messages), open the corresponding Cloudwatch Log group and select the latest Log Stream.

Next Steps

  1. Extend the Interaction Model with additional intents and utterances using the information provided on the Alexa Developer Console.
  2. Adapt the backend (Lambda-function) to your needs using ASK SDK for Node.js

References

Alexa Skill Development

Typescript, Javascript for Alexa Skills

Authentication, Account Linking

About

A self-hosted demo skill for amazon alexa based on terraform and typescript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published