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 CloudFormation CLI Tools for Windows

This guide is based on Windows 7, Service Pack 1. Other versions of Windows may require adjustments to these instructions.

Install the Java Runtime

The CloudFormation CLI tools depend on the Java runtime (JRE), which is not installed by default on Windows 7. You must have version 5 or later installed on your system. You can use either the 32-bit or 64-bit version.

To check your Java version, open a Command Prompt and change your directory to the the JRE bin folder. This is typically C:\Program Files (x86)\Java\jre#\bin (32-bit) or C:\Program Files\Java\jre#\bin (64-bit), where # represents the version number. Then type:

> java -version

The return value is in the form 1.major_version.minor_version. If, major_version is less than 5, or the command returns an error, you must update your JRE. To download the latest version of Java, go to http://java.com/download.

Note

Note your Java version number and whether it is 32-bit or 64-bit. Make sure to use the same version consistently throughout this procedure.

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.

Unzip the Archive

Once you've downloaded the AWS CloudFormation CLI archive, unzip it by following these steps:

  1. Open Windows Explorer and navigate to your Downloads directory.

  2. Right-click the .zip file and click Extract All on the context menu.

The extracted directory will be AWSCloudFormation-cli\AWSCloudFormation-#.#.#, where #.#.# represents the current version number (currently 1.0.12).

Install the CLI Tools

You can install the CLI Tools in any directory you choose, though for simplicity, it's good to install them in a location within your home directory. It is identified on Windows by the USERPROFILE environment variable, and is usually C:\Users\name, where name is your Windows user name. Once you begin using CloudFormation, you'll likely want to install command-line tools for other AWS services, so we'll install the CloudFormation CLI tools within a directory designed to house all of these toolsets, called awstools.

Note

You can name the directory anything you want. If you do this, however, remember to consistently substitute the location you've chosen for the awstools directory we'll use throughout this guide.

To prepare the install location

  1. Open a Terminal window by doing one of the following:

    • Open the Windows Start menu, click All Programs, then Accessories, and finally Command Prompt.

    • Open the Windows Start menu and type Command in the Search Programs and Files text box. Click the Command Prompt entry.

  2. In your command prompt, create the installation directory by typing:

    > mkdir %USERPROFILE%\awstools

    This will create a directory (if it doesn't already exist) called "awstools" in your home directory.

You can use %USERPROFILE%\awstools as the base directory for all AWS toolsets you want to install. Here, we'll concern ourselves only with installing the CloudFormation CLI tools.mo

To install the CLI tools

  1. Change your working directory to %USERPROFILE%\awstools. You can do this on the command-line with:

    > cd %USERPROFILE%\awstools
  2. Move the unzipped AWSCloudFormation-#.#.# directory to the install location, by typing:

    > move Downloads\AWSCloudFormation-cli\AWSCloudFormation-#.#.# .

    Downloads represents your downloads folder, which depends on your browser. Typical values are C:\Downloads or %USERPROFILE%\Downloads. Replace all instances of # with the appropriate version number for your installation.

Configure the CLI tools

Change your working directory to the install directory, which you can do on the command line by typing

cd %USERPROFILE%\awstools\AWSCloudFormation-#.#.#

Replace all instances of # with the appropriate version number for your installation. In this directory, you will find a file named credential-file-path.template. This file can be used to supply your AWS credentials to the tools automatically so you won't need to pass these credentials to the tools on the command-line every time you run them.

Adding your credentials to this file can save you time, but can also present a security risk if your system is used by others, since your security key will be stored as plain text on your system.

If you don't have your AWS credentials handy, you can view them by logging into the AWS console and selecting Security Credentials from the My Account / Console menu at the top of the screen. On the page, click Access Credentials to see your access key under the Access Key ID heading. Your secret key can also be viewed here by clicking the show button under the Secret Access Key heading.

Important

Do not share your secret access key with anyone! With your secret access key, anyone would be able to use AWS services 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 CloudFormation CLI tools 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 use the CLI tools.

To add your AWS credentials to the AWS credential file

  1. Go to the AWS CloudFormation CLI tools install directory from the command-line, using:

    > cd %USERPROFILE%\awstools\AWSCloudFormation-#.#.#

    This assumes that you installed the CLI tools into %USERPROFILE%\awstools. If you did not, replace the location in the example above with the pathname to the location where you installed the CLI tools. Replace all instances of # with the appropriate version number for your installation.

  2. Copy or rename the credential-file-path.template file to a filename of your choosing (you can even use credential-file-path.template as the filename, but I prefer something that better describes its purpose). For the purposes of this article, we'll use "myAWSCredentials.txt":

    > copy credential-file-path.template myAWSCredentials.txt
  3. Edit the file with your favorite text editor, enter your AWS credentials, then save and close the file. The file should contain two lines in it, like this:

    AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE
    AWSSecretKey=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

    Note: These are example values, and won't work for an actual connection to AWS. Instead, use your own AWS security credentials here.

Finally, you'll need to add a few environment variables to your system. Since you'll be using the CloudFormation CLI tools from the command-line, you can simply add these to your %USERPROFILE%\profile.bat file.

To add the CloudFormation CLI tools environment variables:

  1. Edit %USERPROFILE%\profile.bat in your favorite editor. If it does not exist yet, create it.

  2. In %USERPROFILE%\profile.bat, add the following lines:

    REM CloudFormation CLI tools setup
    set JAVA_HOME=C:\Program Files (x86)\Java\jre#
    set AWS_CLOUDFORMATION_HOME=%USERPROFILE%\awstools\AWSCloudFormation-#.#.#
    set AWS_CREDENTIAL_FILE=%AWS_CLOUDFORMATION_HOME%\myAWSCredentials.txt
    set PATH=%PATH%;%AWS_CLOUDFORMATION_HOME%\bin
    

    Replace all instances of # with the appropriate version number for your installation..

    • This example assumes that you installed the CLI tools into %USERPROFILE%\awstools. If you did not, replace $USERPROFILE with the pathname to the location where you installed the CLI tools.

    • This example uses the 32-bit version of the JRE. To use the 64-bit version, set JAVA_HOME to "C:\Program Files\Java\jre#, where # represents the Java version number (usually 6 or 7).

    • If you did not add your AWS access keys to an external file (such as the myAWSCredentials.txt file specified above), you should not assign the AWS_CREDENTIAL_FILE environment variable. Instead, remove or comment-out that line.

  3. Create a shortcut that starts a command-line prompt and then loads your batchfile. To do this:

    1. Right-click your Windows desktop and choose New, then Shortcut in the context menu.

    2. In the Create Shortcut dialog, type C:\Windows\System32\cmd.exe /k %USERPROFILE%\profile.bat and click Next.

    3. Choose a name for your shortcut, such as AWS Command Prompt, and click Finish to create the shortcut on your Windows desktop.

  4. To load your environment variables, quit your current command prompt session and then restart it by using the shortcut you just created.

  5. Test your installation by running cfn-cmd:

    > cfn-cmd

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