- / software craftsman
- / devopper
- / hardware hacker
- / IoT
Writing an Amazon Echo/Alexa app for Meetup.com Events
A small intro to Amazon Echo, AWS Lambda (Python), and the Alexa Toolkit.
Recently, I had to give an impromptu Python talk for PyStPete since it can be… difficult … to get people to volunteer talks. I had just hacked on a pair of Amazon Echos to tell each other Yo Momma Jokes at a hackday we had at work, so I had Amazon Echo hacks on the brain. I figured, why not do a quick talk on getting started with Amazon Echo in the realm of Python and throw in a little AWS Lambda foo while I was at it.
A quick overview of terms
- Amazon Web Services (AWS) - Amazon’s vast offering of “things” as a service.
- AWS Lambda - Serverless architecture for serving code that interacts with Amazon Echo.
- AWS Cloud Watch - Interface for viewing logs for Lambda code being executed.
- Alexa Skills Toolkit - The SDK development portal for configuring Echo apps.
- GitHub Repo for Example Code - An example app you can configure for any meetup.
Setting up AWS Lambda
You’ll actually need an AWS account. This will involve putting in your billing info (incase you get crazy). This app alone will not cost you anything (most likely).
Create an IAM Role to access AWS Lambda with.
- Go to the IAM page.
- Click Roles.
- Click Create New Role
- Role Name = lambda_basic_execution
- Click Next Step
- Select AWS Lambda as the Role type.
- Search for and select AWSLambdaBasicExecutionRole.
- Click Next Step and Create Role.
Create the Lambda function that will execute the code we’ll write to interact with Amazon Echo.
- Go to the Lambda page.
- Create a Lambda Function
- Filter blueprints by “Python”
- Select hello-world-python.
- To the left of the “Lambda” icon, you’ll seee a gray outlined box. Select it and click Alexa Skills Kit.
- Name = SomeFunctionName
- Description = Some description that makes sense.
- Runtime = Python 2.7 (I know, why no Python 3?!)
- Go with Code entry type = Edit Code Inline and leave the default for now.
- Handler = lambda_function.lambda_handler
- Existing role = lambda_basic_execution
- Accept any further defaults and click Next and Create Function.
We now have a Lambda function for use with our Alexa app.
- Go to the Lambda page and you should see your new function.
- Click it.
- Look in the top right and you’ll see a ARN field with a long string of text to the right of it. Something like “arn:aws:lambda:us-east-1:975070732451:function:MyFunction”. Save this. You’ll need to add this to your Alexa Skills Kit setup.
Configuring Alexa Skills Kit
Now that we have a Lambda function setup, we can create an Alexa skill that will use it.
- Go to the Alexa Skills Kit page.
- Click Add New Skill.
- Skill type = Custom Interaction Model
- Name = Name of the skill that is displayed to customers in the Alexa app.
- Invocation Name = The command to ask Alexa to do.
- Click Next.
- Intent Schema = contents of the example intent schema
- Sample Utterances = contents of the example utterances file
- Click Next.
- Select AWS Lambda ARN (Amazon Resource Name)
- Copy in the ARN of the AWS Lambda you created earlier.
- Click Next.
- Notice the handy dandy test screen. This is used to simulate talking to your device to facilitate easier testing.
- Click Next.
- STOP! No need to continue further. Everything will work with your AWS account / Echo. The information left to fill out is only for when you want to publish your app to the Echo app store.
Push application code to AWS Lambda
Check out and configure the code that handles interactions with AWS Lambda and the Meetup API.
You’ll need an API token for the Meetup API. This will be set in the
settings.py file below. Assuming you are logged in, you can find your Meetup API token here.
You’ll also need to know the URL of your meetup. The bold bit: www.meetup.com/Saint-Petersburg-Python-Meetup/. This will also be set in
# Check out the GitHub repo. git clone firstname.lastname@example.org:LyleScott/Amazon-Echo-Next-Meetup-App.git cd Amazon-Echo-Next-Meetup-App # Copy the template. cp settings.dist.py settings.py # ... edit settings.py ... # You can use a graphical program to create a .zip file. # Just make sure all files are in the *root* of the zip file. zip -r app.zip *
- Use the example above to configure/zip files that will be uploaded to AWS Lambda.
- Go to the AWS Lambda page.
- Click on the Lambda function you created earlier.
- Code entry type = Upload a .ZIP file.
- Click Upload and browse and find app.zip and select it.
- Click Save.
Test It Out
Alexa, ask (invocation name) (phrase).
Alexa, ask Py Saint Pete when the next meetup is.
Hopefully you’ll get a valid response. If you get an error, see the AWS Cloud Watch logs that correspond to your Lambda function.