Subscribe to our blog to get the latest articles straight to your inbox.

Before you dive into this post, you’ll want to check out our previous blog post, which outlines how lazysusan works, what dependencies you'll need to get started, and how to deploy one of the example skills. (Go ahead — we’ll wait.)

Got it? Great. Now, you’re ready to get your hands dirty and build an Alexa skill from scratch.

The Alexa skill we’re building in this post is a fortune cookie skill. It’s a good example to walk through together: simple enough that we don’t need a ton of code, but complex enough to fully acquaint you with the lazysusan framework.

Assumptions

We know what they say about making assumptions — but in this case, we need them so that we can hit the ground running. So, we’re going to assume that you::

1. Set up all of the dependencies from the previous blog post.
2. Know how to program well enough that you can read some simple Python code.
3. Understand YAML syntax.
4. Have a decent understanding of state machines.

Directory Structure

We’ll start by laying out the directory structure and creating each file and folder — and don’t worry: we’ll do it one a time, explaining each as we go along.

You should create a folder called fortune_cookie to house all of your project files.

Amazon Developer Portal Meta Data

The skill_information.txt, intent_schema.json, and skill_information.txt files are purely for documentation purposes on how you should create in the Amazon Developer Portal. If you work with others to build out an Alexa skill, it’s a good idea to version control this information. The files are included here, so you can just copy and paste the values into the Amazon Developer Portal.

skill_information.txt

intent_schema.json

{  "intents": [       {      "intent": "StartFortuneCookieIntent"    },    {      "intent": "AMAZON.YesIntent"    },    {      "intent": "AMAZON.NoIntent"    }  ]}

sample_utterances.txt

Environments

In lazysusan applications, you’ll probably have multiple deployment environments. Typically:

• a development environment where you can test changes that you make;
• a staging environment where changes the team makes can be tested by stakeholders; and
• a production environment, which is available to anyone who enables your Alexa skill.

To handle this gracefully, you need an envs folder as well as an environment file for each development stage you wish to deploy. Here are the contents of envs/development for this project:

envs/development

AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  AWS_REGION=us-east-1 DEV_NAME=development  LAZYSUSAN_SESSION_STORAGE_BACKEND=cookie  LAZYSUSAN_LOG_LEVEL=logging.INFO

The environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY_ID, AWS_REGION, and DEV_NAME are solely used for deployment. The remaining environment variables adjust the functionality of lazysusan to fit the needs of your skill. Such environment variables are thoroughly covered in the lazysusan documentation.

Makefile

The Makefile helps us script certain actions that we need to take when working with our Docker container. Simply copy and paste this file.

Makefile

Make Command Descriptions

$make libs This command installs all of the Lambda function dependencies for you so that you won’t have to find them yourself. $ ENV=*** make shell

This command launches your docker container so that you can perform deployments and run specific tests.

$make deploy After running make shell, this command performs a full deploy to the region specified by the ENV variable. $ make function

Similar to make deploy, this command only deploys code changes to the specified ENV. Keep in mind: if you make any changes to the environment, such as your env file or serverless.yml file, you’ll need to perform the full deploy to make those changes in the deployed environment.

Lambda Function

Up until now, every step we’ve completed has been setup and configuration to make writing the Lambda function as easy and painless as possible. The Lambda function is the actual skill logic that will be used whenever an Alexa device requests output on the user's behalf. Now that we’re ready to start writing code for the Lambda function, we need to create a few files and install the necessary dependencies with these commands.

functions:    fortune:    handler: handler.main    events:      - alexaSkill

While the possibilities are endless with serverless, this config just deploys the included files to Lambda, sets some environment variables, and sets up the Alexa Skills Kit Trigger for your Lambda function. Now that you have the deployment configured, deploy away:

$ENV=development make shell# The following should be executed inside of the docker container$ make deploy

Once the deploy command is completed, point your skill to the Lambda function and test it out in the Amazon Developer Portal or on an Alexa enabled device.

For more information about developing Alexa skills with lazysusan, we encourage you to read the documentation, where everything is covered in great detail.