Start tracking your progress
Trailhead Home
Trailhead Home

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.

Create a Lambda Function

  1. 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. Sign In to the Console button
  2. 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.
  3. 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).
  4. Click Create a function.
  5. Click AWS Serverless Application Repository.
  6. Search for the application named alexa-skills-kit-nodejs-factskill in the search box, then hit Enter.
  7. Click the application name, alexa-skills-kit-nodejs-factskill.
  8. Click Deploy. Once the process is finished, you see a message at the top of the page indicating Application successfully deployed.
  9. Under the Resource header, click the application name, alexaskillskitnodejsfactskill. This brings you to the Lambda function page.
  10. Scroll down the page to the Function code header.
  11. 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.
  12. 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.

ARN value appearing in top-right corner

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.

Customization

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.

Lambda Function Testing

Now for the million-dollar question: Does it work?

  1. Click Test in the upper-right part of the page.
  2. 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!).
  3. Choose an Event name. You can keep it easy and call it StartSession.
  4. Click Create.
  5. Click Test next to your StartSession test.
  6. You should now see a new green box that says Execution result: succeeded. Below this is the actual response that your Lambda function generated.

Screenshot of green box that says: Execution result: succeeded

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!

Resources

We won't check any of your setup. Click Verify Step to go to the next step in the project.

retargeting