Go Serverless with Alexa Skills

Krishna Teja
spawn-ai
Published in
2 min readNov 29, 2016

I have recently started working with Alexa Skills Kit and being quite acquainted with flask have started using the flask-ask module which works very similar. One of the ways to publish and deploy our Alexa Skill written using flask-ask is using AWS lambda.

Why use Lambda?
Its a developers instinct I believe why I wanted to use AWS lambda.
One of the main reasons I love using lamda is that I can run my code without having to provision or manage servers. You pay only for the compute time you consume — there is no charge when your code is not running. With Lambda, you can run code for virtually any type of application or backend service — all with zero administration.

With serverless deployments, the web application only exists during the span of a single HTTP request. The benefit of this is that there’s no configuration required, no server maintenance, no need for load balancers, and no cost of keeping a server online 24/7.

So how do you make your Alexa Skill code run on lambda? Enter Zappa.

First, you’ll need to set up your “virtual environment” and install the following modules as shown below into it, like so:

$ virtualenv env
$ source env/bin/activate
$ pip install flask flask-ask zappa awscli
$ zappa init

This part is a little tricky since you will have to install all the python dependencies that your project requires to have or the code will fail to run.

Then configure your AWS credentials by:

$ aws configure

Enter in your ACCESS_KEY, SECRET_ACCESS_KEY, REGION and OUTPUT.

Then create a new file called zappa_settings.json where we’ll load in our Zappa configuration.

{
"production": {
"s3_bucket": "your_s3_bucket",
"app_function": "main.app"
}
}
*Here the main.app is the name of the class you want to call.

This defines an environment called ‘production’ (you may want to add ‘development’ and ‘staging’ environments as well), defines the name of the S3 bucket we’ll be deploying to, and points Zappa to a WSGI-compatible function, in this case, our Flask app object.

Now, we’re ready to deploy. It’s as simple as:

$ zappa deploy production

And our serverless microservice is alive! Just use the https end point that is generated by zappa after deploying your skill and you are ready to GO LIVE!!

This is one of the contests that I have recently participated in and have leveraged Zappa.

For more info check out https://github.com/Miserlou/Zappa.

We went from zero to production in just 5 days for a Hackster competition.

Looking for more innovative apps to go live!

--

--