AWS CloudFormation
User Guide (API Version 2010-05-15)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Configuring the AWS CloudFormation CLI Tools for Linux

This guide is based on Ubuntu Linux 11.10. Specific steps may vary for other versions of Linux, but these instructions should apply to most modern Linux distributions.

The CLI Tools Require Java Runtime Environment 1.5

The AWS AWS CloudFormation CLI requires the Java Runtime Environment (JRE) 1.5 or later. Depending on your Linux distribution, the runtime may already be installed. To see what version of Java is installed on your computer, open a terminal window. At the command prompt, type the following, and then press Enter:

$ java -version

If this command returns an error or reports a Java version earlier than 1.5, or returns an error, you must update your JRE to at least version 1.5 or install the runtime if it is not already installed. For information about installing the JRE, go to the Java website.

Download the CLI

Before setting anything up on your system, you'll need to download the AWS CloudFormation CLI tools. To download them, go to the AWS CloudFormation Command Line Tools page, and then click Download.

The downloaded file is named AWSCloudFormation-cli.zip.

Install the CLI

You can install the AWS CloudFormation CLI tools in any directory you choose. For simplicity, though, it's a good idea to install them in a location within your home directory (typically /home/name, where name is your Linux user name). Once you begin using AWS CloudFormation, you'll probably want to install command-line tools for other AWS services, so we'll install the AWS CloudFormation CLI tools within a directory designed to house all of these toolsets, called .awstools.

Note

A directory with an initial period (.) will be hidden by default to the file manager and to the ls command. We hide the directory so that it won't clutter the view of your home directory. If you don't want it hidden, name it simply awstools or anything else you choose. It won't affect how the tools work as long as you consistently substitute your chosen location for the .awstools directory that we'll use throughout this guide.

To prepare the installation directory

  1. Open a terminal window. To open a terminal window on Ubuntu Linux:

    1. Open the Ubuntu menu (called Dash home).

    2. In the search box, type term.

    3. Click Terminal to open the terminal window.

  2. Create the installation directory. At the command prompt, type the following, and then press Enter:

    $ mkdir ~/.awstools

    This command will create a hidden directory (if it doesn't already exist) called .awstools in your home directory. You can use ~/.awstools as the base directory for all AWS toolsets that you want to install. For now, we'll just concern ourselves with installing the AWS CloudFormation CLI tools.

To install the CLI tools

  1. Change your working directory to ~/.awstools. At the command prompt, type the following, and then press Enter:

    $ cd ~/.awstools
  2. Unzip AWSCloudFormation-cli.zip, which you downloaded earlier, in the installation directory. At the command prompt, type the following, and then press Enter:

    $ unzip ~/Downloads/AWSCloudFormation-cli.zip

    This command will create a subdirectory called AWSCloudFormation-#.#.#, where each # represents part of the version number.

  3. (Optional) Link to the installation directory. At the command prompt, type the following, replacing #.#.# with the version number of the downloaded tools, and then press Enter.

    $ ln -s AWSCloudFormation-#.#.# cfn

    For example, to link to version 1.0.11 of the tools, you would type:

    $ ln -s AWSCloudFormation-1.0.11 cfn

    Linking to the installation directory makes it easy to switch to a new version of the tools. It also gives you the ability to easily switch to another version by simply overwriting the link to point to the installation directory of the version you want to use.

Configure the CLI tools

Within the installation directory, you will find a file named credential-file-path.template. You can use this file to automatically supply your AWS credentials to the AWS CloudFormation CLI instead of supplying them with each command you issue.

Caution

Adding your credentials to this file can save you time, but it can also present a security risk if your system is used by others, because the file stores your access key ID and secret key as plain text.

To view your AWS access credentials

  1. Go to the Amazon Web Services website at http://aws.amazon.com.

  2. Click My Account/Console, and then click Security Credentials.

  3. Under Your Account, click Security Credentials.

  4. In the spaces provided, type your user name and password, and then click Sign in using our secure server.

  5. Under Access Credentials, on the Access Keys tab, your access key ID is displayed. To view your secret key, under Secret Access Key, click Show.

Important

Do not share your secret access key with anyone. Anyone who has access to your secret access key will be able to use AWS services in your name and charge usage fees to your account.

If you don't want to keep your credentials in a file on your system, you can skip the next procedure, and instead pass your credentials directly to the AWS AWS CloudFormation CLI with the --I ACCESSKEY and --S SECRETKEY arguments, replacing ACCESSKEY and SECRETKEY with your AWS credentials. You will need to do this every time you issue an AWS command.

To add your AWS credentials to the AWS credential file

  1. Open the terminal if you don't have it open already, and change your working directory to the AWS CloudFormation CLI installation directory. For example, if you made a link to your installation directory called cfn as suggested previously, At the command prompt, type the following, and then press Enter:

    $ cd ~/.awstools/cfn
  2. (Optional) Copy or rename credential-file-path.template For this example, we'll use myAWSCredentials.txt. At the command prompt, type the following, and then press Enter:

    $ cp credential-file-path.template myAWSCredentials.txt
  3. Edit the file with your favorite text editor (both gedit and vi are installed by default on Ubuntu), enter your AWS credentials as shown, and then save and close the file.

    AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE
    AWSSecretKey=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

    Note: These are only example values. Enter your own AWS security credentials in the file.

Finally, you'll need to add a few environment variables to your system. Because you'll be using the AWS CloudFormation CLI from the command-line, you can simply add these variables to your ~/.bashrc file.

To add the AWS CloudFormation CLI tools environment variables:

  1. Edit ~/.bashrc (or the equivalent terminal startup file for your Linux variant) in your favorite editor. If this file does not exist yet, create it.

  2. In ~/.bashrc, add the following lines, substituting the appropriate directories on your own computer:

    # AWS CloudFormation CLI tools setup
    export JAVA_HOME="/usr/lib/jvm/default-java/jre/"
    export AWS_CLOUDFORMATION_HOME="$HOME/.awstools/cfn"
    export AWS_CREDENTIAL_FILE="$AWS_CLOUDFORMATION_HOME/myAWSCredentials.txt"
    export PATH="$PATH:$AWS_CLOUDFORMATION_HOME/bin"

    If you did not add your AWS access keys to an external file (such as the myAWSCredentials.txt file specified earlier), you should not include the AWS_CREDENTIAL_FILE environment variable.

    Note

    On Ubuntu Linux, default-java is a link to the default Java installation, which is typically OpenJDK. OpenJDK works fine with the AWS CloudFormation command-line tools. If you prefer a different Java runtime, you can reset default-java to point to your preferred runtime location, or you can set the location of your preferred runtime as the value of JAVA_HOME in ~/.bashrc.

  3. To load your environment variables, either quit and restart the terminal or, at the command prompt, At the command prompt, type the following, and then press Enter:

    $ source ~/.bashrc
  4. Test your installation by running cfn-cmd. At the command prompt, type the following, and then press Enter:

    $ cfn-cmd

    This command will list all of the available AWS CloudFormation CLI commands, their usage, and the available options for cfn-cmd itself (there are two options: help and version).