question

Matt Kruse avatar image
Matt Kruse asked

Solved: "Serverless" Skill w/ Account Linking (100% AWS)

Tonight I was finally successful in connecting all the pieces to make a skill that uses Account Linking and is built using only AWS Services: 1) Lambda 2) S3 Hosting 3) API Gateway 4) DynamoDB I'd like to write up a description of exactly how to do this, since finding your way around AWS is a nightmare. But I'm not sure I'll ever have the time, so here's the high-level summary: 1) Create an S3 bucket and get its external-facing HTTPS url. Put your static account linking content (index.html, etc) in this bucket, and point the skill's account linking url to this S3 url. 2) Create a lambda function that will hold both your account linking code and your alexa skill code 3) Enable CORS on the Lambda function 4) Use API Gateway to create a POST endpoint to your Lambda skill 3) When the user enables your skill, your index.html from your S3 bucket is loaded and displayed to the user 4) It then uses ajax to call back to the Lambda API Gateway url and submit the authentication info to your lambda function 5) The lambda function generates an accessToken, connects to DynamoDB, and inserts a record for this user 6) The lambda function returns a redirect url back to the index.html page (as supplied by amazon when account linking is enabled) 7) The index.html redirects back to Amazon, passing the accessToken along with it. 8) The skill is then enabled, and Alexa will pass the accessToken with each request 9) On launch of the skill, the lambda function queries DynamoDB for the user record using the accessToken, retrieves the user details, and then does its normal function, whatever that is. (Wow, is that even English?!) Conceptually, I don't think this is too complicated. I could see the high-level architecture and sequence of events pretty clearly. In practice, it's insanely complicated to get AWS configured correctly so all these parts talk to each other. Very manual, and a LOT of clicks. I've looked into using the new(ish) JAWS framework, but it doesn't do everything I need. Bummer. Now that I have this working, I think I will put in another hour or two to refine this skill and submit it. Even though I was going to be done with skills development for a while, I couldn't help but figure out this puzzle and build something very useful. I'll let you know what it is once I submit it for certification. ;) Any questions?
alexa skills kitsubmission testing certification
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jjaquinta avatar image
jjaquinta answered
Are you [i]sure[/i] you don't want to become a co-author of my book? :-) You could have your name in lights! Think of the celebrity! Think of your share of the $0.66 average earnings each day! ... Will you open source your code afterwards? I guess that's only a small part of it. The instructions are the big part. And given how Amazon likes to tweak their UIs, those are likely to change every few months. :-( Maybe you should take commissions. What are your rates?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Kruse avatar image
Matt Kruse answered
Sorry, but my "wish I had time to do" list is already full, and writing part of a book is not on it. :) I would like to create a boilerplate project for skills that want to use this exact scenario. I think it would help a lot of people get up and running. But I think that more than half the difficulty would be just defining every part of the AWS setup - there are so many things to do! If I could figure out how to use the AWS CLI, I could automate the provisioning of S3, Dynamo, API Gateway, etc. I just don't know enough about that. In fact, I'm not even sure I did it correctly manually. IAM still confuses the hell out of me! This stuff is fun to figure out and build, but as we've all talked about before, there isn't much incentive to really go much further with it. I like the idea of sharing everything I've learned and built with the community, but in reality it would take many hours of work to do so, and I have so many other things I want to do with my time. There just isn't a strong enough incentive to put all that time into it. Having my name in lights is not a big motivator for me. ;)
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.