Categories
Software

Building your own Alexa skill using AWS Lambda and Python (Part 1)

While I resisted the pull of the ‘smart speaker’ for a little while, I have to admit having Amazon Music and an Echo has been one of the most enjoyable things I’ve bought for myself over the past couple of years. Maybe it’s my age, but voice activation still seems very cool to me, but I’m middle aged, quite often tired and like most adults, I have a lot of dull stuff to do in my life. ‘Aha…… Katie, why not automate away that toil……’

So yes, that’s why I thought it would be fun (and help me reawaken some tech skills) to build my own app. Of course, their is info out there already on this, but I found a lot of it stopped a bit short, or jumped right into the code writing. So here’s my write up of the first part of it which is the basic interaction between you and Alexa. After that I’ll do write ups of how to use lambda a bit more to actually have functionality.

You will need:

  • A developer account for the Alexa Skills Kit (ASK)/ Alexa Developer Console. developer.amazon.com
  • An AWS account: aws.amazon.com . You can get an account with a free tier to use AWS lambda assuming you don’t exceed 1 million requests a month. (You’ll need to provide a payment method to get the account)
  • Some basic python coding skills
  • A brilliant idea!

Alexa Developer Console

This is where you create the voice interaction model. It’s a web based IDE- nothing to download, and it has it’s own test environment. I used the following tutorial, but I found it simpler to write up my own notes.

Here’s my translation of the Alexa terms:

  1. A name for your skill ie. ” Alexa, open <insert cool name here>”- that’s the invocation name. I recommend making it simple as you may forget it….. I did, more than once.
  2. Intents could be translated as ‘functions’ of the app. With utterances being the phrases you may say, to initiate those ‘functions’.
  3. Within the utterances, you can set variables- which translates as ‘slots’. You can set the available value of the slot.
  4. Set your endpoint- ie. link it to the code in AWS Lamda

Example:

Invocation: Bin check

Intents: Check_next

Utterance: When is the next {bin_type} collection

Intent Slots: bin_type

Slot Type: waste_type with user utterances: garden waste; rubbish etc.

Once you have it all set up you’ll need to ‘build model’.

But really, that won’t do anything on it’s own. That’s where lambda comes in.

To get ready for the next bit I recommend going to the Endpoint menu to show your ‘Skill ID’ which you’ll need for later:

AWS Lambda:

For this I assume you’ve set up an AWS account and are on the Lambda service.

Firstly, You’re going to need to create a new function.

Choose a name (I went for ‘Bins’), and choose the language in which you’ll write the function. I went for Python and left the default IAM selection.

Now press ‘Create function’.

Once created you’ll see the IDE with the following at the top. This is how you link it to the ASK work you did earlier. At the following :

Click “Add trigger”. You want to choose “Alexa Skills Kit”

The following should appear and you can add the Skill ID I highlighted earlier. Click Add.

You now want to do the reverse. At the top right of the functions screen you should see the following. Copy this ready to link it back.

Right. Now back to the ASK console. Back to the Endpoints section and copy and past your function ID in. Notice you have regional options if perhaps in your Alexa skill, a reference to pants might warrant a different response if your end user is in the UK or the US………

Save the end points and …. ta da……. you’ve linked your alexa skill to a function! Sure it doesn’t do anything yet….. but hey. That’s part 2…..

By Katie

Tea drinker extrodinaire; lover of the outdoors and nature.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.