DEV Community

loading...

Serverless Alexa Skill with DynamoDB

danquack profile image Daniel Quackenbush ・2 min read

As the rise of personal assistants grow, I thought I’d learn a new skill and attempt to roll my own. I’ve seen various different example of users using Alexa to report on metrics, as well as different maintainability models. Of what I could find, none combined both - dynamic sentence return with ease of maintainability.

My first Alexa skill was created as a reporting tool, where I have different appliances report in different numeric values, such as how many users have clicked on an event, or the total network packets sent through my router for a given period of time. I then used these metrics and through regex replacement, have Alexa report back to me, in a clean, easy to understand, database defined sentence.

In my DynamoDB table I have three attributes, the metric, the total_count, and the response. When an intent is called I take the name of the intent, call it MyExampleIntent, and look for “my example” (casing to space) within the database. If it is there, I then take the response value - ex. The total number of my example is {total_count} - and return that with the numeric value from the total_count attribute. Therefore, when anyone wants to add a new intent, they can update the serverless file with the intent name and sample utterances, and then add a new item to the table with that metric. On the next deploy of the skill, you’ll see the new metric. It’s as simple as that!

Check out the project on my GitHub and let me know what you think.

GitHub logo danquack / Serverless-Alexa-with-Dynamodb

An Alexa facts-based skill designed to report metrics out of dynamodb

Serverless Alexa with Dynamodb


Build Status

This sample alexa skill is a facts based skill designed to report metrics out of dynamodb. The idea is that something external would update dynamodb, which would then be read through alexa.

Prereqs

  1. Install nodejs (https://nodejs.org/en/download/)
  2. Install the aws cli and set up a profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)
  3. Create a developer alexa account (https://developer.amazon.com/alexa)
  4. Read vendor documentation (https://github.com/marcy-terui/serverless-alexa-skills)

Devtime dependencies

  1. A dynamodb table must be created for facts
    • The table should contain a primary key of "metric" i. The keys should be lowercase space separated words
    • The table should have a "total_count" and "response" attributes
  2. OATH2 is configured for sls alexa (https://serverless.com/blog/how-to-manage-your-alexa-skills-with-serverless/)
    • Provided in these instruction is creating your skill. Create the skill, and then add the the skill id to environment variables. sls alexa create --name $ALEXA_SKILL_NAME --locale en-US --type custom
  3. The following environment variables should be…

Discussion

pic
Editor guide