Alexa Skill using AWS Lambda in Typescript
This is a sample Alexa Skill handler based on aws-lambda-typescript.
- Install the Serverless Application Framework as a globally available package:
$ npm install serverless -g
Verify that Serverless was installed correctly:
$ serverless -v
- Setup AWS credentials:
Save the credentials to the
serverless config credentials --provider aws --key YOUR_ACCESS_KEY --secret YOUR_SECRET_KEY
default profile will be used by default. If you want to use another, you can pass the
--aws-profile argument to the
serverless commands. E.g.:
serverless deploy --aws-profile Work
Clone this repository.
Install the dependencies:
$ npm install
- Customize the name of your service by changing the following line in the
- Customize the alexa skill id by changing the following line in the
- alexaSkill: amzn1.ask.skill.xx-xx-xx-xx-xx
During development, it's a pain to always have to deploy your lambda function to see your changes. There is a better way, you can connect Alexa to your local environment instead of Lambda, without having to make any modifications to your Lambda functions.
- First, we will need an HTTPS endpoint. You can use ngrok for this (it's free), or any other similar tools.
$ ./ngrok http 3980
This will give you an HTTPS endpoint which will proxy all requests to your local server (something like
- Go to your skill's dashboard at the Endpoint section.
- Instead of
AWS Lambda ARN, select
- Now copy the https url from
ngrokand paste it in the
- For the
SSL certificate type, make sure you select
My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority, otherwise it will not work.
- Save the changes in the Alexa developer console.
- Inside the project, run
npm start. This will start a local http server using
nodemonwhich will serve your lambda function.
Now, Alexa will be connected to your server, so you don't need to deploy to Lambda anymore.
Since the process is using
nodemon, making any changes to the code will automatically restart the server, so your changes will be reflected to Alexa immediately.
For more info, check
package.json and the aws-lambda-typescript documentation.
What you can find in the code
The project contains the base structure of a project, with a dummy handler for the
LaunchRequest intent which responds with
- Add example test, ideally with lambda-tester, but currently it doesn't have a Typescript definition
devDependenciesbeing packaged as well
Open sourced under the MIT license.