Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

AWS Lambda, ASK API cut Amazon Echo development times

The Amazon Echo beta revealed some new uses for the popular voice-command device. Our expert explains how to configure it and why the ASK API is instrumental in its functionality.

A new development in AWS Lambda is the Alexa Skill Kit API, which does what developers in the Echo beta program...

were able to tinker with. The hardware picks up voice recognition and has a very natural text-to-speech synthesis program. But it's not perfect; it lacks certain basic tasks end users may ask it for. Enter the ASK API -- a key in Echo development.

The ASK API allows developers to write software to respond to user input on Echo and returns developer responses that are spoken to the user. With ASK, developers need an API for the Echo to call functions, but they can also use Amazon Web Services (AWS) Lambda. That means if the software is unused, there is no cost. If it is used, AWS customers are billed for the computing resources they use. Many companies fall into the free-usage tier, as Amazon allows for one million function calls per month.

Initiating the Ask API

When I first heard about how the ASK API would work, the first thing I thought about was tying Alexa into Twilio to send out SMS messages. After all, who do I always ask questions? Simply saying "Alexa, ask my wife …" seemed natural, so let's start building that system.

Let's assume you've signed up for AWS, Lambda and the Echo ASK systems. Additionally, all of the code that I use in this example, including the final product, is available as an open source project on Github.

First, check out the code locally and take a look at the typical structure for a Lambda function for the Alexa Skills Kit. Lambda functions can be hooked up directly to Amazon Echo or triggered via Simple Notification Service, Simple Storage Service or DynamoDB events. You can also attach Lambda resources to the Amazon API Gateway or run them directly using the API. After checking out the code, zip it up and upload it to your AWS account through the Lambda console.

On the blueprint section, click the "Skip" button:

Lambda console

On the next page click the "Upload" button and attach the zip file you created from the code in the Github repository. Then fill out the name and change the "Handler" to "app.handler."

Github repository

The "Role" is the Identity and Access Management (IAM) role for the associated Lambda function. You can have Lambda create a default role for you by choosing "* Basic Execution Role." Follow the prompts, and it will create a role automatically.

I had some issues getting the automatic IAM role creation to work while using Google Chrome, but it worked fine after switching to Safari. If you have a pop-up blocker in your browser, you may need to disable it for the auto-creator to work.

After filling out the criteria, click the "Next" button to create the function in Lambda. Once the function is created, click on the "Event Sources" tab and add an "Alexa" event source.

Event Sources tab in Lambda
Alexa Skills Kit as the event source

Adding the ASK configuration

Once the Lambda function is configured, it's time to set up the ASK configuration. Log in to the Amazon Echo Skills Console and click "Get Started" under the Alexa Skills Kit.

Amazon Echo Skills Console

Then click "Add a New Skill."

On the next screen, fill out the basic information for the Alexa Skill, including a name, invocation name (what users will say to activate your application), version string and the endpoint for the application. For the endpoint, make sure to switch to AWS Lambda and copy in the Amazon Resource Networks from the Lambda application. On the next page, the "Intent Schema" and the "Sample Utterances" are two important fields to complete.

For the Intent Schema, copy in the following code:

{
   "intents": [
   {
      "intent": "SetPhoneNumber",
         "slots": [
         {
            "name": "PhoneNumber",
            "type": "LITERAL"
         }
      ]
   },
   {
      "intent": "AskMyWifeQuestion",
      "slots": [
      {
         "name": "Question",
         "type": "LITERAL"
      }
      ]
   }
   ]

This schema sets up two different intents that Alexa can call. The first is the simple "SetPhoneNumber" intent, which takes a single argument "PhoneNumber." The second intent is called "AskMyWifeQuestion," which also takes a single argument "Question."

The second part of this setup is the "Sample Utterances," which helps Alexa determine which intent to fire and what text to add to each argument. For this section, enter some samples of the types of text Alexa should accept, along with a mapping of how to fill out each argument. The first word in this field is the intent name. Each line should be an intent name, followed by the text that will match that intent. Note that intent names must be one word, no spaces. For anything you want to be sent in as an argument, specify it as {sample string|SLOTNAME}.

For example:

SetPhoneNumber My Wife's Number Is
{five five five five five five five five five five|PhoneNumber}

AskMyWifeQuestion {What's for Dinner|Question}

AskMyWifeQuestion {Hello|Question}

The first line calls the "SetPhoneNumber" intent by saying "My Wife's Number Is … " and then a number -- we have to use the spelled-out numbers as the samples. The second one allows a generic type of string, "What's for Dinner?" You can add as many sample strings as you'd like, including strings that only take certain parts of the text to send to the Question argument, such as:

AsMyWifeQuestion to {come home|Question}

This would ignore the "to" part and send just "come home" as the question.

Once you've set up these fields, click "Next" and the Skill Kit app will be ready to test on Amazon Echo.

Increasing the functionality

When Alexa receives a command, the Lambda function executes the "Skill" library. Additional intents can be added to the Skill as the second argument. The function "askMyWifeQuestion" in the app.js file contains the basic skeleton for working with an Alexa intent, and after it is called, it fires the AskMyWifeQuestion intent. The first argument is the intent object; the second is a session object that is kept while interacting with Alexa. The third argument is the callback function to call to respond to the user.

To include an additional intent, add it to the Schema and Sample Utterances, and then specify it in the app.js skills definition. You can take the code and modify it to your specific needs -- and distribute it and share it.

Next Steps

How do I manage and monitor AWS Lambda code?

Use Git to version-control AWS app development

AWS Node.js integration eases app development

This was last published in August 2015

PRO+

Content

Find more PRO+ content and other member only offers, here.

Essential Guide

AWS re:Invent 2015: A guide to Amazon's sold-out event

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What types of applications have you developed using Lambda?
Cancel

-ADS BY GOOGLE

SearchCloudApplications

TheServerSide

SearchSoftwareQuality

SearchCloudComputing

Close