October 3, 2022


Collaborate Learn Innovate

Build An Alexa Trivia Skill

Image with Alexa skill development services written on it

This Alexa sample skill is a template for a basic trivia skill. Provided a list of interesting questions about a topic, Alexa will select a question at random and ask it of the user when the skill is invoked.

  1. User Voice Interface
  2. Lambda Function
  3. Connect VUI To Code
  4. Testing
  5. Customization
  6. Publication
An image containing tools design


  1. Go to the Amazon Developer Portal. In the top-right corner of the screen, click the “Sign In” button. (If you don’t already have an account, you will be able to create a new one for free.)
  2. Once you have signed in, move your mouse over the Your Alexa Consoles text at the top of the screen and select the Skills (New) Link.
  3. From the Alexa Skills Console (New Console) select the Create Skill button near the top of the screen.
  4. Give your new skill a Name. This is the name that will be shown in the Alexa Skills Store, and the name your users will refer to. Push Next.
  5. Select the Custom model at the top of the page to add to your skill and select the Create Skill button at the top right.
  6. Build the Interaction Model for your skill
    1. On the left-hand navigation panel. Select the Invocation tab. Enter a Skill Invocation Name. This is the name that your users will need to say to start your skill.
    2. Next, select the JSON Editor tab. In the text field provided, replace any existing code with the code provided in the Interaction Model (make sure to pick the model that matches your skill’s language), then click “Build Model”.

Note: You should notice that Intents and Slot Types will auto-populate based on the JSON Interaction Model that you have now applied to your skill. Feel free to explore the changes here, to learn about IntentsSlots, and Utterances open our technical documentation in a new tab.

  1. Optional: Select an intent by expanding the Intents from the left side navigation panel. Add some more sample utterances for your newly generated intents. Think of all the different ways that a user could request to make a specific intent happen. A few examples are provided. Be sure to click Save Model and Build Model after you’re done making changes here.
  2. If your interaction model builds successfully, proceed to the next step. If not, you should see an error. Try to resolve the errors. In our next step of this guide, we will be creating our Lambda function in the AWS developer console, but keep this browser tab open, because we will be returning here on Page #3: Connect VUI to Code.

If you get an error from your interaction model, check through this list:

  1. Did you copy & paste the provided code correctly?
  2. Did you accidentally add any characters to the Interaction Model or Sample Utterances?

Setting Up A Lambda Function Using Amazon Web Services

In the first step of this guide, we built the Voice User Interface (VUI) for our Alexa skill. On this page, 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.

  1. Go to http://aws.amazon.com and sign in to the console. If you don’t already have an account, you will need to create one. If you don’t have an AWS account, check out this quick walkthrough for setting it up.
  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. AWS Lambda only works with the Alexa Skills Kit in these regions: US East (N. Virginia), US West (Oregon), Asia Pacific (Tokyo) and EU (Ireland). Make sure you choose the region closest to your customers. ß 
  4. Click the orange “Create function” button. It should be near the top of your screen. (If you don’t see this button, it is because you haven’t created a Lambda function before. Click the blue “Get Started” button near the centre of your screen.)
  5. There are three boxes labeled “Author from scratch”, “Blueprints” and “Serverless Application Repository”. Click the radio button in the box titled “Serverless Application Repository” We have created a repository as a shortcut to getting everything set up for your skill.
  6. Search for the application repository named “alexa-skills-kit-nodejs-triviaskill”. You can find it using the provided search box.
  7. Click on the repository. This repository will create the Lambda function, add Alexa Skills Kit as it’s trigger, and sets up an IAM role for you. It will also add the code from this GitHub repo and include it’s dependencies to your Lambda function so that you don’t have to upload it yourself.
  8. Click the deploy button at the bottom of the page.
  9. Wait for the status of all resources to change to CREATE_COMPLETE
  10. Click the Test App button to go to the Lambda console.
  11. Open the function that was just created by clicking on it.
  12. If you want to secure this Lambda function follow the instructions found here
  13. Scroll down the page until you see a section called Function code.
  14. Copy the provided code from here into the Lambda function code box. Delete the contents of the code box, and paste the contents of the new code. Click “Save”.
  15. You should see the Amazon Resource Name (ARN) a unique identifier for this function in the top right corner of the page. Copy the ARN value for this Lambda function for use in the next section of the guide.

Connecting Your Voice User Interface To Your Lambda Function

On page #1 of this guide, we created a voice user interface for the intents and utterances we expect from our users. On page #2, we created a Lambda function that contains all of our logic for the skill. On this page, we need to connect those two pieces together.

  1. Go back to the Amazon Developer Portal and select your skill from the list. You may still have a browser tab open if you started at the beginning of this tutorial.
  2. Select the Endpoint tab on the left side navigation panel.
  3. Select the “AWS Lambda ARN” option for your endpoint. You have the ability to host your code anywhere that you would like, but for the purposes of simplicity and frugality, we are using AWS Lambda. (Read more about Hosting Your Own Custom Skill Web Service.) With the AWS Free Tier, you get 1,000,000 free requests per month, up to 3.2 million seconds of compute time per month. Learn more at aws.amazon.com/free. In addition, Amazon now offers AWS Promotional Credits for developers who have live Alexa skills that incur costs on AWS related to those skills.
  4. Paste your Lambda’s ARN (Amazon Resource Name) into the textbox provided for Default Region.
  5. Click the Save Endpoints button at the top of the main panel.
  6. Click the “Next” button to continue to page #4 of this guide.

Testing Your Alexa Skill

So far, we have created a Voice User Interfacea Lambda function, and connected the two together. Your skill is now ready to test.

  1. Go back to the Amazon Developer Portal and select your skill from the list. You may still have a browser tab open if you started at the beginning of this tutorial.
  2. Open the Test Pane, by selecting the Test link from the top navigation menu.
  3. Enable Testing by activating the Test is enabled for this skill slider. It should be underneath the top navigation menu.
  4. To validate that your skill is working as expected, invoke your skill from the Alexa Simulator. You can either type or click and hold the mic from the input box to use your voice.
  1. Type “Open” followed by the invocation name you gave your skill in Step 1. For example, “Open Reindeer Trivia”.
  2. Use your voice by clicking and holding the mic on the side panel and saying “Open” followed by the invocation name you gave your skill.
  3. If you’ve forgotten the invocation name for your skill, revisit the Build panel on the top navigation menu and select Invocation from the sidebar to review it.
  4. Ensure your skill works the way that you designed it to.
  1. After you interact with the Alexa Simulator, you should see the Skill I/O JSON Input and JSON Output boxes get populated with JSON data. You can also view the Device Log to trace your steps.
  2. If it’s not working as expected, you can dig into the JSON to see exactly what Alexa is sending and receiving from the endpoint. If something is broken, AWS Lambda offers an additional testing tool to help you troubleshoot your skill.
  3. Configure a test event in AWS Lambda. Now that you are familiar with the request and response boxes in the Service Simulator, it’s important for you to know that you can use your requests to directly test your Lambda function every time you update it. To do this:
    1. Enter an utterance in the service simulator, and copy the generated Lambda Request for the next step.
    1. Open your Lambda function in AWS, open the Actions menu, and select “Configure test events.”
    1. Select “Create New Test Event”. Choose “Alexa Start Session” as the Event Template from the dropdown list. You can choose any test event in the list, as they are just templated event requests, but using “Alexa Start Session” is an easy one to remember.
    1. Type in an Event Name into the Event Name Dialog box. Delete the contents of the code editor, and paste the Lambda request you copied above into the code editor. The Event Name is only visible to you. Name your test event something descriptive and memorable. For our example, we entered an event name as “startSession”. Additionally, by copying and pasting your Lambda Request from the service simulator, you can test different utterances and skill events beyond the pre-populated templates in Lambda.
    1. Click the “Create” button. This will save your test event and bring you back to the main configuration for your lambda function.
    1. Click the “Test” button to execute the “startSession” test event.

This gives you visibility into four things:

  • Your response, listed in the “Execution Result.”
    • A Summary of the statistics for your request. This includes things like duration, resources, and memory used.
    • Log output. By effectively using console.log() statements in your Lambda code, you can track what is happening inside your function, and help to figure out what is happening when something goes wrong. You will find the log to be incredibly valuable as you move into more advanced skills.
    • A link to your CloudWatch logs for this function. This will show you all of the responses and log statements from every user interaction. This is very useful, especially when you are testing your skill from a device with your voice. (It is the “Click here” link in the Log Output description.)
  • Other testing methods to consider:
  1. Echosim.io – a browser-based Alexa skill testing tool that makes it easy to test your skills without carrying a physical device everywhere you go.
  2. Unit Testing with Alexa – a modern approach to unit testing your Alexa skills with Postman and Amazon API Gateway.
  3. If your sample skill is working properly, you can now customize your skill.

Customize the Skill to be Yours

At this point, you should have a working copy of our Trivia skill. In order to make it your own, you will need to customize it with data and responses that you create. Here are the things you will need to change:

  1. New data. You will need to provide a set of trivia for your topic. We recommend a minimum of 25, but a total closer to 100 offers a better experience.
    1. Open a copy of index.js. If you haven’t already downloaded the code for this project, you can find a copy of index.js here on GitHub. You can use a simple, lightweight code editor like AtomSublime Text, or VSCode, but you also have the option to edit the code directly in your Lambda function.
    1. Search for the comment “TODO: Replace this data with your own.” This is the data for our skill. You can see that it is a simple list of facts.
    1. When you have replaced the data in index.js, copy the contents of your file to your Lambda function. This should be as simple as copying the text and pasting it into the code box for your Lambda.
  2. New sentences to respond to your users. There are several sentences and responses that you will want to customize for your skill.
    1. Go back to your copy of index.js.
    1. Look for the comment “TODO: The items below this comment need your attention.” This is the beginning of the section where you need to customize several text strings for your skill.
    1. Continue through index.js until you reach the bottom of the file. This will ensure that you cover each of the values that you need to update.
  3. New language. If you are creating this skill for another language other than English, you will need to make sure Alexa’s responses are also in that language.
  4. For example, if you are creating your skill in German, every single response that Alexa makes has to be in German. You can’t use English responses or your skill will fail certification.
  5. Once you have made the updates listed on this page, you can click “Next” to move on to Publishing and Certification of your skill.

Get Your Skill Certified and Published

We are almost done! The last step is to add the metadata that your skill will use in the Skill Store. This page will walk you through the remaining steps to launch your skill!

  1. Select the Launch link from the top navigation menu.
  2. Fill out the form fields per the guidance on the screen. Hover over the question mark icons for details regarding each respective field. Fields marked with an Asterisk, are required!
  3. Take the time to get these right so that your skill will pass certification!
  4. Write your skill descriptions.
  5. Spend some time coming up with an enticing, succinct description. This is one of the few places you have an opportunity to attract new users, so make the most of it! These descriptions show up in the list of skills available in the Alexa app and the skills store.
  6. For your example phrases, come up with the three most exciting ways a user can talk to your skill.
Common Failure Points for Example Phrases
Example phrases must adhere to the supported phrases.
Example phrases must be based on sample utterances specified in your Intent Schema.
Your first example phrase must include a wake word and your invocation name.
Example phrases must provide a contextual response.
  • Make sure that each of your example phrases are a perfect match with one of your Sample Utterances. Incorrect example phrases are one of the most common reasons that skills fail certification, so we have provided a short list of things to consider as you write your example phrases:
    • Choose three example phrases that are likely to be the most common ways that users will attempt to interact with your skill. Make sure that each of them works well, and provides an excellent user experience.
  • Create your skill’s icons. You need two sizes of your icon: 108x108px and 512x512px.
    • Make sure you have the rights to the icons you create. Please don’t violate any trademarks or copyrights.
    • If you don’t have software to make icons, try one of these free options:
  1. GIMP (Windows/Mac/Linux)
  2. Canva (Web)
  3. Paint.NET (Windows)
  4. Inkscape (Windows/Mac/Linux)
  5. Iconion (Windows/Mac)
    1. To make it easier to get started, we’ve created blank versions of these icons in both sizes for many formats:
  1. PSD
  2. PNG
  3. GIF
  4. PDF
  5. JPG
  6. SVG
  7. PDN – for Paint.NET
  8. XCF – for GIMP
  9. Choose the most appropriate category for your skill.
  10. Provide a comprehensive list of keywords for users that are searching for new skills. This is an optional field, and searching the Alexa app or the skill store will also find the words in your Skill Name and descriptions, so you don’t need to overdo it. That being said, if there are words that you want users to find your skill with, you should include them here. Separate the keywords with commas.
  11. Privacy Policy URL. This is an optional field, and should not be required for this Trivia skill sample. You can leave it blank.
  12. Terms of Use URL. This is also optional, and you can leave it blank.
  13. When you’re ready, click Save and Continue at the bottom of the screen to move onto Privacy & Compliance
    1. Does this skill allow users to make purchases or spend real money? For this trivia skill, the answer is no. For future skills, make sure you answer this appropriately.
    1. Does this Alexa skill collect users’ personal information? Again, for this trivia skill, the answer is no. If you do collect information about a user, such as names, email addresses, phone numbers, and so forth, ensure that you answer Yes to this question.
  15. Answering “yes” to this question will also require you to provide a link to your Privacy Policy at the bottom of the page.
    1. Is your skill directed to children under the age of 13? Because you customized this skill with data you provided, it is possible that you created a skill that targets children under the age of 13. For this trivia skill, the answer is no because it doesn’t target a specific age group.
      1. Factors to consider in determining if this skill is directed to children under 13 include:
  1. Subject matter of the skill
  2. Presence of child-oriented activities and incentives
  3. Type of language used in the skill
  4. Music and other audio content in the skill
  5. How the skill is described and marketed
  6. Intended audience for the skill

If you’re not sure, please see the FTC’s COPPA Guidance and FAQ for more information.

  1. Export Compliance. Be certain that you agree with all of the conditions. If you do, make sure to check this box, as Amazon requires this permission to distribute your skill around the globe.
  2. Provide testing instructions. Testing instructions give you an opportunity to explain your skill, and any special or possibly confusing features, to the certification team. A value is required in this box.
    1. Since you are using our Sample, make sure to add a sentence to your Testing Instructions referencing the Sample you used. For example:
o    ```
o    This was built using the Trivia Sample.
o    ```
o    This will let the testing team understand what you're providing them, and should decrease the testing time required.    

Note: More details on certification are available here.

  • If you feel that your skill is ready for certification, click the Save and Continue button at the bottom of the page.
  • You’re done with your submission! Here are a few things you might need to know:
    1. Certification can take several days to complete. Please be patient. It takes time because we want to get it right.
    1. Did something go wrong? Our team of evangelists run online office hours every Tuesday from 1-2pm Pacific Time. They can help answer any questions you might have.
    1. Want the coolest t-shirt you’ve ever seen? Every month, we create a brand-new Alexa Developer t-shirt or hoodie and send them out to developers that published a skill that month. You can get yours here if you live in the UShere for the UK, and here for Germany.

Source- https://github.com/alexa/skill-sample-nodejs-trivia/blob/en-US/Readme.md