CodePipeline
User Guide (API Version 2015-07-09)

Tutorial: Create a Pipeline That Deploys an Amazon Alexa Skill

In this tutorial, you configure a pipeline that continuously delivers your Alexa skill using the Alexa Skills Kit as the deployment provider in your deployment stage. The completed pipeline detects changes to your skill when you make a change to the source files in your source repository. The pipeline then uses the Alexa Skills Kit to deploy to the Alexa skill development stage.

Note

To create your custom skill as a Lambda function, see https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-an-aws-lambda-function.html. You can also create a pipeline that uses Lambda source files and a CodeBuild project to deploy changes to Lambda for your skill. For example, to create a new skill and related Lambda function, you can create an AWS CodeStar project. See Create an Alexa Skill Project in AWS CodeStar. For that option, the pipeline includes a third build stage with an CodeBuild action and an action in the Deploy stage for AWS CloudFormation.

Prerequisites

You must already have the following:

Step 1: Create an Alexa Developer Services LWA Security Profile

In this section, you create a security profile to use with Login With Amazon (LWA). If you already have a profile, you can skip this step.

Step 2: Create Alexa Skill Source Files and Push to Your CodeCommit Repository

In this section, you create and push your Alexa skill source files to the repository that the pipeline uses for your source stage. For the skill you have created in the Amazon developer console, you produce and push the following:

  • A skill.json file.

  • An interactionModel folder.

To create source files for your skill

  1. Retrieve your skill ID from the Alexa Skills Kit developer console. Use this command:

    ask api list-skills

    Locate your skill by name and then copy the associated ID in the skillId field.

  2. Generate a skill.json file that contains your skill details. Use this command:

    ask api get-skill -s skill-ID > skill.json
  3. (Optional) Create an interactionModel folder.

    Use this command to generate the interaction model file within the folder. For locale, this tutorial uses en-US as the locale in the filename.

    ask api get-model --skill-id skill-ID --locale locale > ./interactionModel/locale.json

To push files to your CodeCommit repository

  1. Push or upload the files to your CodeCommit repository. These files are the source artifact created by the Create Pipeline wizard for your deployment action in AWS CodePipeline. Your files should look like this in your local directory:

    skill.json /interactionModel |en-US.json
  2. Choose the method you want to use to upload your files:

    1. To use the Git command line from a cloned repository on your local computer:

      1. Run the following command to stage all of your files at once:

        git add -A
      2. Run the following command to commit the files with a commit message:

        git commit -m "Added Alexa skill files"
      3. Run the following command to push the files from your local repo to your CodeCommit repository:

        git push
    2. To use the CodeCommit console to upload your files:

      1. Open the CodeCommit console, and choose your repository from the Repositories list.

      2. Choose Add file, and then choose Upload file.

      3. Choose Choose file, and then browse for your file. Commit the change by entering your user name and email address. Choose Commit changes.

      4. Repeat this step for each file you want to upload.

Step 3: Use ASK CLI Commands to Create a Refresh Token

CodePipeline uses a refresh token based on the client ID and secret in your Amazon developer account to authorize actions it performs on your behalf. In this section, you use the ASK CLI to create the token. You use these credentials when you use the Create Pipeline wizard.

To create a refresh token with your Amazon developer account credentials

  1. Use the following command:

    ask util generate-lwa-tokens
  2. When prompted, enter your client ID and secret as shown in this example:

    ? Please type in the client ID: amzn1.application-client.example112233445566 ? Please type in the client secret: example112233445566
  3. The sign-in browser page displays. Sign in with your Amazon developer account credentials.

  4. Return to the command line screen. The access token and referesh token are generated in the output. Copy the refresh token returned in the output.

Step 4: Create Your Pipeline

In this section, you create a pipeline with the following actions:

  • A source stage with a CodeCommit action where the source artifacts are the Alexa skill files that support your skill.

  • A deployment stage with an Alexa Skills Kit deploy action.

To create a pipeline with the wizard

  1. Sign in to the AWS Management Console and open the CodePipeline console at http://console.aws.amazon.com/codesuite/codepipeline/home.

  2. Choose the AWS Region where you want to create the project and its resources. The Alexa skill runtime is available only in the following regions:

    • Asia Pacific (Tokyo)

    • EU (Ireland)

    • US East (N. Virginia)

    • US West (Oregon)

  3. On the Welcome page, Getting started page, or the Pipelines page, choose Create pipeline.

  4. In Step 1: Choose pipeline settings, in Pipeline name, enter MyAlexaPipeline.

  5. In Service role, do one of the following:

    • Choose New service role to allow CodePipeline to create a new service role in IAM. In Role name, the role and policy name both default to this format: AWSCodePipelineServiceRole-region-pipeline_name. For example, this is the service role created for this tutorial: AWSCodePipelineServiceRole-eu-west-2-MyAlexaPipeline.

    • Choose Existing service role to use a service role already created in IAM. In Role name, choose your service role from the list.

    Note

    Depending on when your service role was created, you might need to update its permissions to support other AWS services. For information, see Add Permissions for Other AWS Services.

  6. In Artifact store:

    1. Choose Default location to use the default artifact store, such as the Amazon S3 artifact bucket designated as the default, for your pipeline in the region you have selected for your pipeline.

    2. Choose Custom location if you already have an artifact store, such as an Amazon S3 artifact bucket, in the same region as your pipeline.

    Note

    This is not the source bucket for your source code. This is the artifact store for your pipeline. A separate artifact store, such as an Amazon S3 bucket, is required for each pipeline. When you create or edit a pipeline, you must have an artifact bucket in the pipeline Region, and then you must have one artifact bucket per AWS Region where you are running an action.

    For more information, see A Quick Look at Input and Output Artifacts and CodePipeline Pipeline Structure Reference.

    Choose Next.

  7. In Step 2: Add source stage, in Source provider, choose AWS CodeCommit. In Repository name, choose the name of the CodeCommit repository you created in Step 1: Create a CodeCommit Repository and Local Repo. In Branch name, choose the name of the branch that contains your latest code update. Unless you created a different branch on your own, only master is available.

    After you select the repository name and branch, a message shows the Amazon CloudWatch Events rule to be created for this pipeline.

    Choose Next.

  8. In Step 3: Add build stage, choose Skip build stage, and then accept the warning message by choosing Skip again.

    Choose Next.

  9. In Step 4: Add deploy stage:

    1. In Deploy provider, choose Alexa Skills Kit.

    2. In Alexa skill ID, enter the skill ID assigned to your skill in the Alexa Skills Kit developer console.

    3. In Client ID, enter the ID of the application you registered.

    4. In Client secret, enter the secret you chose when you registered.

    5. In Refresh token, enter the token you generated in step 3.

      
                                The Step 4: Deploy page for an Alexa
                                    Skills Kit action
    6. Choose Next.

  10. In Step 5: Review, review the information, and then choose Create pipeline.

    
                        The completed pipeline for an Alexa Skills Kit action

Step 5: Make a Change to Any Source File and Verify Deployment

Make a change to your skill and then push the change to your repository. This triggers your pipeline to run. Verify that your skill is updated in the Alexa Skills Kit developer console.