Giter VIP home page Giter VIP logo

alexa-serverless-lambda-template's Introduction

Alexa Template

This project is an Alexa Skill written in JavaScript (ES7). It is intended to be deployed to AWS Lambda, but can also be run via Express server. Deployment and infrastructure is managed by Serverless

npm install -g serverless to install

The provided interaction model has the basic intents: LaunchRequest, CancelIntent, HelpIntent, StopIntent. I also added one additional intent called SayMyNameIntner. When you can say Alexa, ask hello world to say Brian, and it will respond back to you. This is more of an example to see a custom intent with slot filling.

./src/server.js is the entrypoint for running locally ./src/alexa.js is the entrypoint for the lambda function

Please feel free to PR or reach out on GH with any issues.

Setup

  • Create a new Alexa Skill. Note the Application ID.

  • Launch the Skill Builder. Paste the contents of interaction-model.json into the Code Editor. Save and build the model.

  • Configure AWS CLI

aws configure --profile [your-profile-name]
AWS Access Key ID [None]: [YOUR_ACCESS_KEY]
AWS Secret Access Key [None]: [YOUR_SECRET_ACCESS_KEY]
Default region name [None]: us-west-1
Default output format [None]: json
  • Install Node Modules with npm install

  • Load environemnt specific credentials

    • Create a env.yaml file like below and place it in the root directory of the application
    • Add your alexa_app_id key to the env file
  test:
    alexa_app_id: foo
    NODE_ENV: test

  local:
    NODE_ENV: local
    alexa_app_id: abc123

  staging:
    NODE_ENV: staging
    alexa_app_id: abc124

  production:
    NODE_ENV: production
    alexa_app_id: abc125

Deployment

To deploy all functions & serverless changes

sls deploy --stage {environment}

To deploy a single function

sls deploy function -f function-name --stage {environment}

If deploying to a new environemnt for the first time, after the deploy login to the AWS Lambda page for your functino, and copy the ARN. In your Alexa configuration for the specific instance you deployed, update the Service Endpoint Type to AWS Lambda ARN and Paste the AWS Lambda ARN

Run/Debug

This project uses uses babel-node with Express to run/debug the skill locally. ESLint is setup for linting.

Command Description
npm start Start Express server.
npm run start:inspect Start Express server with inspector agent enabled.
npm run lint Run ESLint
npm run lint:fix Run ESLint and automatically fix problems.
npm run test Run All tests in ./test directory.
npm run test:inspect Run All tests in ./test directory with inspector.

Note if chrome inspector does not launch with debugger; you may need to do the following:

In Chrome 60+ there is an item "Open dedicated DevTools for Node" in chrome://inspect/#devices url, (as well as node.js icon in devtools while node is running) The opened inspect window will connect to node.js as soon as it starts or restarts, so there is no need to open it manually each time.

Running Locally

Sometimes Often you need to run locally to debug and test. You can test alexa on your local machine by running this server with node and pointing your alexa skill to it.

  • In the root directory run npm run start which will start the server on port 3000
  • In another shell use ngrok to create a tunnel to your machine ngrok
    • Type ngrok http 3000 and copy the https url it gives you
    • In your skill settings on the alexa dashboard, change your endpoint to https and paste the https url
    • Make sure to select My development endpoint is a sub-domain of a domain that has a wildcard cerficiate
  • Now you can click the Test tab in your alexa dashboard to invoke your skill and it should now route to your localserver

Sentry

I'm using Sentrys wrapper for catching and reporting errors in lambda. You can create a free Sentry account at http://sentry.io/ and add the DSN url in the serverless.yml custom section - If you choose not to use Sentry, everything will still work

alexa-serverless-lambda-template's People

Contributors

kida001 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.