Amazon provides a command line interface (CLI) tool for working with many of its services. For developing Alexa skills, you will need the Alexa Skills Kit (ASK) and Amazon AWS CLI if you choose to implent your intent handlers using AWS Lambda.
AWS Lambda is a serveless computing service that allows developers to deploy and run code on the web without needing to manage any server infrastructure. They can be implemented using a variety of programming languages including Node.js, Java, C#, Go and Python.
The ASK CLI provides a convenient utility to generate and create the artifacts for an Alexa skill:
- Skills manifest
- Interaction model
- AWS Lambda
For this to work, you must first install and configure the AWS CLI. Download and follow the instructions based on your operating system requirements. Be sure to include the AWS CLI binaries in your OS PATH.
Test your AWS CLI installation:
$ aws --version
aws-cli/1.14.50 Python/2.7.14 Windows/10 botocore/1.9.3
Next, head over the AWS Console. You will need to:
- Create an IAM policy for ASK to deploy AWS Lambda functions.
- Create an IAM user and assign the ASK Lambda Deploy policy.
- Click on any of the
Sign In to the Consolebuttons. - Login using the "Root user" (the Amazon account used to sign up for AWS services).
- Select the region
US East (N. Virginia)using the drop-down menu on the top-right. - In the AWS service search box, type
IAMand then select theIAMservice. - Click the
Policiesitem on the left navigation menu. - Click the
Create policybutton. - Click the
JSONtab. - Copy the contents from the file
resources/aws-lambda-deployer-iam-policy.jsonand paste into the text editor. - Click the
Review policybutton. - Enter the policy name, e.g.
AskLambdaDeployer. - Click the
Create policy. - After the policy has been created successfully, click on the
Usersitem on the left navigation menu. - Click the
Add userbutton. - Enter a user name and select
Programmatic accessforAccess type. - Click the
Next:Permissionsbutton. - Click the button
Attach existing policies directlybutton. - Search for and select the IAM policy created in the earlier steps.
- Click the
Next:Reviewbutton. - Click the
Create userbutton. - When the IAM user has been created successfully, the
Access key IDandSecret access keywill be displayed. Click theShowlink to reveal theSecret access key. IMPORTANT: This code is displayed only once, so note it down!
Now you are ready to configure the AWS CLI:
$ aws configure
AWS Access Key ID [None]: ********************
AWS Secret Access Key [None]: ****************************************
Default region name [None]: us-east-1
Default output format [None]: json
- Download and install Node.js.
- Install the ASK CLI:
$ sudo npm install -g ask-cli
- Initialize the ASK CLI. During the initialization, select the default profile and associate an AWS credential. A browser session will be created for you to login, approve and automatically inject the token to the CLI.
$ ask init
-------------------- Initialize CLI --------------------
Setting up ask profile: [default]
? Please choose one from the following AWS profiles for skill's Lambda function deployment.
default
Switch to 'Login with Amazon' page...
Tokens fetched and recorded in ask-cli config.
Vendor ID set as **************
Profile [default] initialized successfully.
Once both CLIs and accounts are set up correctly, the next thing to do is to create your first Alexa skill!
- Use the ASK CLI to generate the artifacts:
$ ask new --skill-name GreeterBot --lambda-name greeter-bot-service
New project for Alexa skill created.
- The following artifacts will be generated:
| Directories/Files | Description |
|---|---|
GreeterBot/ |
Project directory for your Alexa Skill |
.ask/config |
Skill ID and AWS Lambda of the newly created stored here. |
lambda/ |
A Node.js application that deploys to AWS Lambda. |
models/en-US.json |
Contains JSON-formatted Intent Schema files, one for each language/region. |
skill.json |
Skill Manifest - JSON representation of the skill, containing all required metadata. |
- Customize your skill. First, modify the
invocationNameattribute in the filemodels/en-US.json. This is the invocation name that is used to launch the skill, e.g.greeter robot. - Also, update the example phrases in the skills manifest (
skill.json) and replace the phrasehello worldwith the invocation name specified in the interaction model. - Deploy the skill. This may take a while.
$ ask deploy
-------------------- Create Skill Project --------------------
Profile for the deployment: [default]
Skill Id: amzn1.ask.skill.3b9e6eec-b445-4e77-a441-202252f1c54d
Skill deployment finished.
Model deployment finished.
Lambda deployment finished.
- Enable the skill. The skill ID can also be obtained from the file
.ask/configin your project directory.
$ ask api enable-skill -s amzn1.ask.skill.3b9e6eec-b445-4e77-a441-202252f1c54d
The skill has been enabled.
- Test the skill:
$ ask simulate -t "Alexa open greeter robot" -l en-US
- A typical deployment consist of all three phases. Note that you may choose to perform only one of these phases when deploying. See the documentation on the
targetoption for details. - The test can also be tested using the Alexa Console.