{{announcement.body}}
{{announcement.title}}

Docker Image for ASK and AWS CLI

DZone 's Guide to

Docker Image for ASK and AWS CLI

In this article, we discuss how to create a Docker container so that we can use Amazon AWS and ASK CLIs for Alexa Skill development.

· Web Dev Zone ·
Free Resource

The purpose of this container is to be able to use the Amazon ASK CLI and Amazon AWS CLI in a Docker container in DevOps pipelines.

Note: This is a fork from the martindsouza image with these changes:

  1. The image base is the latest LTS version instead of the current version of Node.js.
  2. Added ASK_CLI_VERSION build argument in order to be able to work with different ASK CLI versions.
  3. Added git and zip packages that ASK CLI will use in its commands.
  4. Added Bespoken.
  5. Remove volumes. I think it is not necessary for a simple Docker image that I will use in my DevOps pipelines. In addition, you can use '-v' argument in docker run command whenever you want.

ASK Config

You have to take into account that you have to have an Alexa Developer account to be able to work with this container.

ASK Configure

Running ask configure in v2 and ask init in v1 in the container will ask you a set of questions to create the Alexa credentials. Follow all the steps explained in the official documentation.

In either case, ensure that you pass in -v $(pwd)/ask-config:/home/node/.ask \ (where $(pwd)/ask-config is a location on your host machine) as an option when running the container to preserve the ASK configuration.

Setting Credentials Using Environment Variables

You can store Alexa credentials in environment variables instead of the Alexa credentials file. If the Alexa environment variables exist, ASK CLI uses them instead of the values in the Alexa credentials file. ASK CLI searches for the following Alexa environment variables:

You can use the ASK CLI environment variables in conjunction with or in addition to the ASK CLI configuration file. The following list describes the ASK CLI environment variables.

  • ASK_DEFAULT_PROFILE: Use this environment variable in conjunction with the ASK CLI configuration file. When you set the value of this environment variable to one of the profiles in the configuration file, ASK CLI uses the credentials in that profile.
  • ASK_ACCESS_TOKEN: Use this environment variable to store an Amazon developer access token. When this environment variable exists, ASK CLI uses it instead of the credentials in the configuration file.
  • ASK_REFRESH_TOKEN: Use this environment variable to store an Amazon developer refresh token. When this environment variable exists, ASK CLI uses it instead of the credentials in the configuration file. When this environment variable and ASK_ACCESS_TOKEN both exist, ASK CLI uses this one.
  • ASK_VENDOR_ID: Use this environment variable to store an Amazon developer vendor ID. When this environment variable exists, ASK CLI uses it instead of the one it the configuration file.
  • ASK_CLI_PROXY: Use this environment variable to specify an HTTP proxy for requests made with the ASK CLI.

If you want to know how to get the ASK_REFRESH_TOKEN and ASK_ACCESS_TOKEN, see this page in the Alexa documentation.

If you want to know how to get the ASK_VENDOR_ID, you only have to enter to this page.

If you are using Alexa environment variable you have to add a new profile called __ENVIRONMENT_ASK_PROFILE__ in your .ask/config file

AWS Config

If you plan to use AWS Lambda, you'll need to configure the AWS CLI. To simplify, You can configure it in multiple ways.

In either case, ensure that you pass in -v $(pwd)/aws-config:/home/node/.aws \ (where $(pwd)/aws-config is a location on your host machine) as an option when running the container to preserve the AWS configuration.

AWS Configure

For general use, the aws configure command is the fastest way to set up your AWS CLI installation. When you enter this command, the AWS CLI prompts you for four pieces of information (access key, secret access key, AWS Region, and output format)

Setting Credentials Using Environment Variables

You can store AWS credentials in environment variables instead of the AWS credentials file. If the AWS environment variables exist, ASK CLI uses them instead of the values in the AWS credentials file. ASK CLI searches for the following AWS environment variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

For more information about the AWS environment variables, see Environment Variables in the AWS documentation.

Usage

Get the latest version of the container:

Shell
 




x


 
1
  # Get image
2
 docker pull xavidop/alexa-ask-aws-cli



They're two ways to use the ask CLI for this container described below.

Run ASK CLI Commands

This is an example that shows up how to execute an ask command. After this command is executed, the container will stop.

Shell
 




x


1
docker run -it --rm \
2
  -v $(pwd)/ask-config:/home/node/.ask \
3
  -v $(pwd)/ask-config:/home/node/.aws \
4
  -v $(pwd)/ask-config:/home/node/.bst \
5
  -v $(pwd)/hello-world:/home/node/app \
6
 xavidop/alexa-ask-aws-cli:latest \
7
 ask init -l



Run ASK CLI Commands Interactively

In this example, the container will start directly with the bash console and then you can execute there all the ASK CLI commands you want.

Shell
 




x


1
docker run -it --rm \
2
  -v $(pwd)/ask-config:/home/node/.ask \
3
  -v $(pwd)/ask-config:/home/node/.aws \
4
  -v $(pwd)/ask-config:/home/node/.bst \
5
  -v $(pwd)/app/HelloWorld:/home/node/app \
6
 xavidop/alexa-ask-aws-cli:latest \
7
  bash



Build and Push the Image

For ASK CLI v1:

Shell
 




x


1
docker build --build-arg ASK_CLI_VERSION=1.7.23 -t xavidop/alexa-ask-aws-cli:1.0 .
2
 
3
# Pushing to Docker Hub
4
# Note: not required since I have a build hook linked to the repo
5
docker login
6
docker push xavidop/alexa-ask-aws-cli



For ASK CLI v2:

Shell


Versions

Currently, there are two versions available:

  • 1.0: This image is running the latest version of ASK CLI v1 (1.7.23).
  • 2.0: This image is running the latest version of ASK CLI v2 (2.1.1).

These versions are available in my DockerHub profile

Documentation:

That’s all, folks!  

You can find the code in my GitHub.

I hope it will be useful! If you have any doubts or questions, do not hesitate to contact me or put a comment below.

Happy coding!

Topics:
alexa, ask cli, aws, aws cli, node, tutorial, web dev

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}