# Deploying the skill

Now, you have a working project and are ready to share it with the world. The next step is to hear it come out of your own Alexa Device.

We will be using AWS for the deployment of your skill. You do not need to be familiar with AWS, but if you continue to use it in deploying Alexa skills, it would be valuable to learn more about the AWS services your skill uses.

AWS is one of many options for deployment

AWS is not required to build skills for Alexa or to use Litexa. The compiled output could be deployed in any Node.js compatible environment, but you will be off the beaten path and starting on a new adventure. πŸ—ΊοΈ

# Deployment Prerequisites

Before you deploy your skill, you must have have done the following (and we'd recommend setting these up in this order, too):

  • Create an Amazon Developer Account
  • Create an AWS Account
  • Create a custom IAM Policy for the deployment user derived from the template below:
    • You will need to replace myAccountId and myBucketName with your AWS account ID and desired S3 bucket name, respectively, for it to be valid.

    • Click to show the custom policy template
      {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "IAMRole",
                "Effect": "Allow",
                "Action": [
                    "iam:AttachRolePolicy",
                    "iam:CreateRole",
                    "iam:GetRole",
                    "iam:ListAttachedRolePolicies",
                    "iam:PassRole"
                ],
                "Resource": "arn:aws:iam::myAccountId:role/litexa_handler_lambda"
            },
            {
                "Sid": "Lambda",
                "Effect": "Allow",
                "Action": [
                    "lambda:AddPermission",
                    "lambda:CreateAlias",
                    "lambda:CreateFunction",
                    "lambda:GetAlias",
                    "lambda:GetFunctionConfiguration",
                    "lambda:GetPolicy",
                    "lambda:ListAliases",
                    "lambda:RemovePermission",
                    "lambda:UpdateFunctionConfiguration",
                    "lambda:UpdateFunctionCode"
                ],
                "Resource": "arn:aws:lambda:*:myAccountId:function:*_*_litexa_handler"
            },
            {
                "Sid": "DynamoDB",
                "Effect": "Allow",
                "Action": [
                    "dynamodb:CreateTable",
                    "dynamodb:DescribeTable"
                ],
                "Resource": "arn:aws:dynamodb:*:myAccountId:table/*_*_litexa_handler_state"
            },
            {
                "Sid": "CreateLogGroupListS3Buckets",
                "Effect": "Allow",
                "Action": [
                    "logs:CreateLogGroup",
                    "s3:ListAllMyBuckets"
                ],
                "Resource": "*"
            },
            {
                "Sid": "S3BucketActions",
                "Effect": "Allow",
                "Action": [
                    "s3:CreateBucket",
                    "s3:ListBucket"
                ],
                "Resource": "arn:aws:s3:::myBucketName"
            },
            {
                "Sid": "S3BucketObjectActions",
                "Effect": "Allow",
                "Action": [
                    "s3:PutObject",
                    "s3:PutObjectAcl"
                ],
                "Resource": "arn:aws:s3:::myBucketName/*"
            },
            {
                "Sid": "DescribeLogGroups",
                "Effect": "Allow",
                "Action": "logs:DescribeLogGroups",
                "Resource": "arn:aws:logs:*:myAccountId:log-group:*"
            },
            {
                "Sid": "LogStreamActions",
                "Effect": "Allow",
                "Action": [
                  "logs:DescribeLogStreams",
                  "logs:PutRetentionPolicy"
                ],
                "Resource": "arn:aws:logs:*:myAccountId:log-group:/aws/lambda/*_*_litexa_handler:log-stream:"
            },
            {
                "Sid": "GetLogEvents",
                "Effect": "Allow",
                "Action": "logs:GetLogEvents",
                "Resource": "arn:aws:logs:*:myAccountId:log-group:/aws/lambda/*_*_litexa_handler:*:*"
            }
        ]
      }
  • Create an IAM User with the above custom IAM policy attached. You could name it something like "litexa-deploy".
  • Install the AWS CLI and configure it with your above IAM User credentials.
  • Install the ASK CLI and sign into your Amazon Developer Account, when prompted during ask init. You can choose "Skip" when prompted to select an AWS profile to attach (Litexa handles AWS deployment separately).

# Installation

We've created an extension to help you deploy your skill. To install it, run

npm install -g @litexa/deploy-aws

# Setup

Deploying requires some simple setup. In the Litexa configuration you must specify your deployment module, the s3Configuration.bucketName you want to deploy to, your askProfile, and your awsProfile. By default, Litexa configures your project to deploy with the @litexa/deploy-aws module for the development environment and sets the other options to null.

module.exports = {
    name: '{name}',
    deployments: {
        development: {
            module: '@litexa/deploy-aws',
            s3Configuration: {
                bucketName: null
            },
            askProfile: null,
            awsProfile: null
        }
    },
    extensionOptions: {}
};

NOTE

If your s3Configuration.bucketName doesn't exist in your account, litexa will try to create it for you. Note, S3 bucket names create URLs and so are global across users; the one you request here may not be available. You'll see an error come up to that effect, if that's the case.

Your askProfile name needs to match one that you configured with ask init.

Your awsProfile name needs to match one that you configured with aws configure and should have the IAM Policy listed above applied to it. Note, litexa can't do this part automatically as it's the policy that grants litexa the ability to access AWS!

# Deploy

To deploy, go to your Litexa project root folder and run

litexa deploy

That's it.

This one command will:

  1. Build your project
  2. Upload your project assets to your S3 Bucket (and create the specified bucket, if it doesn't exist)
  3. Infer your language models
  4. Create your skill in the ASK Developer Console
  5. Upload your skill manifest to the ASK Developer Console
  6. Upload each of your language models to the ASK Developer Console per language region you support
  7. Create your Lambda
  8. Bundle your project, zip it up, and push it to Lambda
  9. Create the DynamoDB table for your skill to save data to

Don't worry if this seems like a lot. You can learn about each of these components in depth later. But now you should be able to invoke your skill.

Try it out. Invoke your skill on an Alexa device connected to your Alexa account; just say, "Alexa, open Hello Litexa."

Alexa Simulator

If you don't have an Alexa device you can also visit the ASK Developer Console and try out your skill in the Alexa Simulator.