In the Voice User Interface step, you built the Voice User Interface (VUI) for our Alexa skill. In this step, we will be creating an AWS Lambda function using Amazon Web Services. You can read more about what a Lambda function is, but for the purposes of this guide, what you need to know is that AWS Lambda is where our code lives. When a user asks Alexa to use our skill, it is our AWS Lambda function that interprets the appropriate interaction and provides the conversation back to the user.
-
Go to the AWS Console and sign in.
If you don't already have an account, you will need to create one. Here is a quick walkthrough for setting up an AWS account.
-
Click Services at the top of the screen, and type
Lambda
in the search box. You can also find Lambda in the list of services. It is in the Compute section. -
Check that your AWS region is set to US East (N. Virginia): us-east-1. AWS Lambda only works with the Alexa Skills Kit in four regions: US East (N. Virginia), EU (Ireland), US West (Oregon) and Asia Pacific (Tokyo). Make sure you choose the region closest to your customers.
-
Click the Create function button near the top right of the page.
-
When prompted, make sure that Author from scratch is selected.
-
Set the name of the function.
FeedReader
is sufficient if you don't have another idea for a name. The name of your function will only be visible to you, but make sure that you name it something meaningful. -
Create an AWS Role in IAM with access to DynamoDB, S3 and CloudWatch logs. If you haven't done this before, a detailed walkthrough for setting up your first role for Lambda is available.
-
Create a new IAM role.
-
Select the Service type of the role as Lambda.
-
Add the following policies to the role:
- AmazonDynamoDBFullAccess
- AmazonS3FullAccess
- CloudWatchLogsFullAccess
- Once you've set up your role, click the Create Function button in the bottom right corner.
-
-
From the Add triggers section on the left add Alexa Skills Kit from the list by clicking on it.
-
Once you have selected Alexa Skills Kit, scroll down to the bottom of the page. Under Configure triggers, select Enable for Skill ID verification. A Skill ID Text Box should appear. The value for this input is your Skill ID from the developer portal.
-
Now lets secure this lambda function, so that it can only be invoked by your skill. Open up the developer portal and select your skill from the list. You mays till have a browser tab open if you started at the beginning of this tutorial.
-
Browse to your list of skills in the Alexa Developer Console and click the View Skill ID link. From the popup Skill ID dialog, select and copy the value. It should look something like the following:
amzn1.ask.skill.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
-
Return back to your lambda function in the. You may already have this browser tab open. Otherwise, open the lambda console by clicking here: AWS Lambda Console and selecting the appropriate function. Scroll down to Configure triggers, paste the Skill ID in the Skill ID edit box.
-
Click the Add button. Then click the Save button in the top right. You should see a green success message at the top of your screen. Now, click the box that has the Lambda icon followed by the name of your function and scroll down to the field called "Function code".
-
Set up your local environment to run the deployment script
-
Configure AWS credentials the tool will use to upload code to your Skill. For full details see the instructions on Configuring the AWS CLI.
-
The file should have the format, and include keys you retrieve from the AWS console:
[default] aws_access_key_id = [KEY FROM AWS] aws_secret_access_key = [SECRET KEY FROM AWS]
-
Setup NodeJS and NPM.
-
Get the code and install dependencies:
``` git clone https://github.com/alexa/skill-sample-nodejs-feed.git cd skill-sample-nodejs-feed/lambda/custom npm install ```
-
-
Create an S3 Bucket
In another tab, go to the Amazon S3 Console and create an AWS S3 Bucket with a unique name like
feed-skill-bucket-385123
. The S3 bucket name must be unique across all existing bucket names in Amazon S3. In case of a conflict, retry with another name and append with something like your initials or a random value. -
[OPTIONAL] Create an AWS DynamoDB table You can manually create a table named MyFeedSkillTable with the case sensitive primary key "userId".
-
Configure the Project to Use Your Feed
-
Open
/lambda/custom/configuration.js
file. -
Update the following information to configure the skill:
**appId**: Your Skill's Application ID from the Skill you created at https://developer.amazon.com.<br/> **welcome_message**: A welcome message that will be spoken to the user when they open your skill.<br/> **number\_feeds\_per\_prompt**: The number of items the skill will read each time the user invokes it.<br/> **display\_only\_feed\_title**: A boolean flag that determines whether to speak out the title-only or title and summary of the items in your feed.<br/> **display\_only\_title\_in\_card** : A boolean flag to decide whether to display a card with the title only or title and summary of the items in your feed.<br/> **categories**: The list of RSS feeds you want to include in your Skill. Each feed will be treated as a category.<br/> **speech\_style\_for\_numbering\_feeds**: Naming convention for each item.<br/> **s3BucketName**: Your S3 Bucket Name.<br/> **dynamoDBTableName**: Your DynamoDB Table Name. (If not created, the skill will create it.)<br/>
- A sample configuration :
```javascript let config = { appId : 'amzn1.ask.skill.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', welcome_message : 'Welcome to Feed Skill', number_feeds_per_prompt : 3, display_only_feed_title : true, display_only_title_in_card : true, categories : { 'feed name' : 'http://www.example.com/rss-feed.xml' }, speech_style_for_numbering_feeds : 'Item', s3BucketName : '{YOUR_S3_BUCKET_NAME}', dynamoDBTableName : 'MyFeedSkillBucket' dynamoDBRegion : 'us-east-1' }; ```
-
-
Deploy Your Skill
-
From the commmand-line, go to the
skill-sample-nodejs-feed/lambda/bin/
directory and rundeploy.js
using Node.npm install aws-sdk node deploy.js
-
Go to the the
skill-sample-nodejs-feed/lambda/custom/
directory and zip all of the files. Be sure to only zip the files inside the directory, and not the directory itself. Theindex.js
file needs to be at the root of the zip file. -
Go to the AWS Lambda Console select your Lambda function, locate the Function code section and upload the file by selecting "Code entry type" as "Upload a .ZIP file".
-
Configure the rest of your function
- Scroll to the Basic Settings section.
- Change the Timeout to 30 seconds, since feeds can become an issue.
- Leave the defaults for everything else.
- Note the ARN of the Lambda you've created, which you'll need later.
-
-
Update the skill interaction model.
- During the deploy, a copy of the interaction model was created and named
en-US-updated.json
that contains the categories specified from the configuration file. Locate that file in the /models directory. - Open the file and copy its contents back into the Intents JSON Editor of the Alexa Developer Console.
- Updating the contents of the interaction model will update the invocation. Doublecheck that you have the invocation name you want to use and save and build the model.
- During the deploy, a copy of the interaction model was created and named
-
After you create the function, the ARN value appears in the top right corner. Copy this value for use in the next section of the guide.