Connect an Alexa Skill to a .Net Lambda Method
Custom Alexa Skills can be implemented in many languages, but using .Net for the back end logic is my personal favorite. Once you have a Lambda method defined and working using .Net, you create an Alexa Skill that uses that Lambda. The process is slightly different from the one you use for the other languages, though.
Create the Alexa Skill
You begin by creating the Alexa Skill in the normal way. Go to the Alexa Developer Console and click Create Skill. Enter your skill name, but choose “Custom” for the model and “Provision your own” for the host method. Then click Create Skill.
When asked to choose a template, choose “Start from Scratch”
When the process finishes you will be on the Build screen.
Choose the Skill Invocation Name and give your skill a name. This is the name you will speak when you want to activate your skill. For example, if we name it “brads lambda skill” we would say “Alexa, open brads lambda skill”.
When you are done click Save Model, then Build Model.
Avoid naming your skill anything with “Hello World” in it. The Alexa Voice Services often confuses this name with the built in Alexa Skill “Hello World” and it will appear your skill is not working.
The part that comes next is a bit of the chicken-and-the-egg. We need a Lambda to assign to the endpoint of the skill, but we need a skill (and its ID) to grant permissions in the Lambda.
For now, copy the skill ID to the clipboard.
Go to the Admin panel for the Lambda you want to wire up to the Alexa skill. Choose the Configuration tab and the Triggers sub-tab. Click Add Trigger and add the Alexa Skills Kit as the trigger. Choosing this will also give you a box to paste in the Skill ID of the Alexa Skill you copied.
You should see a Success message and a new trigger associated with the Lambda.
What this has done is setup the Lambda so the Alexa Skill can call it. However, we have not told the Alexa Skill what lambda to call yet. We will do that next.
Setting Endpoint in your Alexa Skill
Copy the ARN from the Lambda you want to connect to your skill.
Return to the Alexa Developer Console where you were specifying the endpoint for your Alexa Skill. Paste in the ARN from the Lambda into the Default Region box. Save the endpoints.
Now we can test our new skill against our Lambda. Go to the Test tab in the Alexa Developer Console. If you see “Test is disabled for this skill”, just set the combo box to “Development”.
At the top left corner, type in “Use {my skill}” where {my skill} is the name you gave to your skill. For this tutorial, we called it “brads alexa skill” so we type that. We should see the proper response from the lambda method.
And that’s it. Your skill is connected to your Lambda and is ready to go.
You can test your skill on any Alexa enabled device you own. However it will only be available on devices that are connected to the AWS account that created the skill. When you are ready to publish your skill for public consumption, check back here for how to do it.