This is a CDK Pattern to deploy an Alexa Skill backed by a Lambda Function and a DynamoDB Table.
NB: This is slightly more complicated than the normal patterns because Alexa is an Amazon product as opposed to an AWS one so you need to setup an Amazon Developer Account with permissions to deploy the skill
Some References:
Author | Link |
---|---|
AWS | Build An Engaging Alexa Skill |
AWS | ASK CLI Docs |
AWS | Starter Alexa Skill Code |
AWS | Implementing Persistent Storage In Your Fulfillment Lambda |
Unfortunately these steps cannot be skipped or shortened as you need to configure an Amazon developer account and acquire an OAuth 2.0 Refresh token that allows you to deploy your skill using CloudFormation.
1. Create an Amazon Developer account
Alexa is an Amazon product even though it can be deployed through AWS you still need to have a separate Amazon Developer account
2. Create a Developer Account Security Profile.
Open the Developer Account Security Profile page and feel free to use whatever values you want for the Security Profile Name and Description. The Privacy Notice URL must be a valid URL format but does not need to be a valid URL. Once you create your security profile, navigate to the Web Settings
tab and add the following as Allowed Return URLs
:
Keep these values safe as we will use them in a second.
You will need this to deploy the CDK stack anyway but for the next step we need to associate Alexa with our AWS Account so this is crucial
Alexa needs to associate your Amazon Developer Account with your AWS Account. The easiest way to do this is to run ask configure
after you have installed the Alexa Skills Kit CLI
We are going to use Postman to fetch a new OAuth 2.0
token
Follow this guide : Setup Postman OAuth 2.0
request
Set the following key/values in the request:
Field | Value |
---|---|
Grant Type | Authorization Code |
Callback URL | http://127.0.0.1:9090/cb |
Auth URL | https://www.amazon.com/ap/oa |
Access Token URL | https://api.amazon.com/auth/o2/token |
Client ID | {YOUR_CLIENT_ID} |
Client Secret | {YOUR_CLIENT_SECRET} |
Scope | alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test alexa::ask:catalogs:read alexa::ask:catalogs:readwrite |
A Pop-Up should show up prompting you to log into your Developer account. Log in and you will be redirected to Postman where you should have a refresh_token
to use in the next steps. Make sure you select the refresh_token
and not the Access Token
from the postman response (scroll down in the response!).
Visit the Customer Details Page for your Amazon Developer Account and make a note of your "vendor ID"
You need to add your ClientID, ClientSecret, Refresh Token and VendorID to the skill resource which can be found in the-alexa-skill/typescript/lib/the-alexa-skill-stack.ts
vendorId: 'foo',
authenticationConfiguration: {
clientId: 'foo',
clientSecret: 'bar',
refreshToken: 'foobar'
},
- Navigate to the Alexa Developer Console, or follow this link - https://developer.amazon.com/alexa/console/ask
- If you see a skill named "CDK Patterns Sample" in your Alexa Skills list then it has successfully been uploaded! Now we just need to test the skill itself.
- Select the CDK Patterns Sample skill by clicking on the name.
- On the next page, select "Test" at the top of the screen.
- Amazon will ask if you'd to use your microphone or not. This is entirely optional as you may test Alexa using either voice commands or the text box provided.
- Change the "skill testing is enabled in:" option from "Off" to "Development" if needed.
- Either type or say "CDK Patterns" (Case sensitive if typing) and wait for a response.
- The response should be "Hey, it's Pancakes the CDK Otter here, what would you like to know?"
- For further testing, either type or say "What patterns do you have?"
- The response should be "I have many patterns for you to see! For example, there is" followed by three pattern names randomly picked from CDK Patterns.
- Now we just need to confirm that it is interacting with DynamoDB correctly.
- Go to the AWS Console and navigate to DynamoDB. Open your tables and find the one corresponding to TheAlexaSkillStack.
- Confirm that one item is in the table (It should have 2 attributes and a UserID). If it does then congratulations! Everything works!