Build the Backend Service
In this step, we create 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 response back to the user.
- Go to http://aws.amazon.com and sign in to the console. If you don't already have an account, you need to create one. If you don’t have an AWS account, check out this walkthrough with video example for setting it up.
- Click Services at the top of the screen, and type
Lambdain the search box. You can also find Lambda in the list of services. It is in the Compute section.
- Check your AWS region in the upper-right part of the screen. AWS Lambda only works with the Alexa Skills Kit in two regions: US East (N. Virginia) and EU (Ireland). Make sure you choose the region closest to your customers. If you’re not sure, it’s safe to start with US East (N. Virginia).
- Click Create a function.
- Click AWS Serverless Application Repository.
- Search for the application named
alexa-skills-kit-nodejs-factskillin the search box, then hit Enter.
- Click the application name, alexa-skills-kit-nodejs-factskill.
- Click Deploy. Once the process is finished, you see a message at the top of the page indicating Application successfully deployed.
- Under the Resource header, click the application name, alexaskillskitnodejsfactskill. This brings you to the Lambda function page.
- Scroll down the page to the Function code header.
- This sample code has been provided for you by the Alexa Skills Kit team in order to power the space facts skill. Any changes you wish to make to the facts or to the skill are made here.
- Scroll back to the top of the page until the ARN value appears in the top-right corner. Copy this value for use in the next section of the guide.
Congratulations, you’ve just built a Lambda function! Feel the power coursing through you. It’s sort of like midichlorians, except it’s about serverless architectures and not about mystical, telekinetic powers.
Now that you have a function, here are some guidelines on how to customize what’s inside the skill. We’re not going to go too in-depth here, but this can help get you started. These tips apply toward the inline code editor using the Function code editor while you are viewing your Lambda function.
Look for the line containing const data = [ . This is the start of the section that holds the different space facts returned by the skill. If you want to add, remove, or change the details of those facts, change it in here. Follow the same format as the other entries to make sure you get all the required fields.
To understand more about how to respond to Alexa and what other tools are at your disposal, read the documentation with the Alexa Skills Kit SDK for Node.js. There are many different examples that cover how to respond with a question, show the user a card, and more.
Now for the million-dollar question: Does it work?
- Click Test in the upper-right part of the page.
- In the Sample event template dropdown, find Amazon Alexa Start Session. This is a simple request that mimics what Alexa sends if someone says, “Alexa, open Space Facts” (or the awesome invocation name that you chose!).
- Choose an Event name. You can keep it easy and call it
- Click Create.
- Click Test next to your StartSession test.
- You should now see a new green box that says Execution result: succeeded. Below this is the actual response that your Lambda function generated.
If you’re interested in learning more about this testing process, check out the AWS Lambda documentation to for more information.
Now that we have a working Lambda function, we’re ready to plug it in to our skill to get it working end to end. We’ve done the hard stuff, now it’s time for some fun!
- AWS Lambda: https://aws.amazon.com/lambda/
- AWS Lambda Manual Testing: http://docs.aws.amazon.com/lambda/latest/dg/get-started-invoke-manually.html
- AWS Identity and Access Management: http://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html
We won't check any of your setup. Click Verify Step to go to the next step in the project.