Infrastructure & Automation

Install and configure TaskCat on Microsoft Windows 10

One of the eight best practices of deployment automation with AWS CloudFormation templates is to implement test automation with TaskCat. Manual testing is a tedious process of deploying templates, waiting on results, and cleaning up stacks created in your AWS account. TaskCat automates all of this for you. It deploys templates into the AWS Regions and Availability Zones specified in a configuration file, logs results, then deletes the resources created by the test. Thus, you can focus on the performance of your templates instead of worrying about unforeseen charges from resources that you fail to delete.

TaskCat, an open-source tool available on GitHub, is not natively supported on Microsoft Windows. This might leave Windows users wondering how they can automate their template testing. In this post, we explain how to install and configure TaskCat on Windows 10 with Windows Subsystem for Linux 2 (WSL 2). Follow the walkthrough we provide to configure a Linux environment on Windows 10, install TaskCat, and use TaskCat to validate an AWS CloudFormation deployment.

About this post
Time to read ~8 min.
Time to complete ~40 min.
Cost $0
Learning level Intermediate (200)
AWS services AWS CloudFormation

Process overview

The procedure we walk through in this post contains the following steps:

  1. Configure a Linux environment on Windows 10 using WSL 2.
  2. Install Docker Desktop.
  3. Install TaskCat and Python library for Docker Engine API.
  4. Clone a test repo and deploy it with TaskCat.

For the test repo, we chose the Remote Desktop Gateway (RD Gateway) Quick Start for its lightweight architecture. This Quick Start uses an AWS CloudFormation template to automate the deployment of the reference architecture shown in Figure 1. This architecture includes virtual private cloud (VPC) with two Availability Zones and an Auto Scaling group of RD Gateway instances in the public subnets.

Quick Start architecture for Microsoft RD Gateway on the AWS Cloud

Figure 1: Quick Start architecture for Microsoft RD Gateway on the AWS Cloud

Prerequisites

For the procedure, you must have the following:

  • An AWS account. If you don’t have an AWS account, sign up at https://aws.amazon.com.
  • Access to the AWS Management Console.
  • A GitHub account. If you don’t have a GitHub account, sign up at https://github.com/.
  • A version of Windows 10 that supports WSL 2.
    • Version 1903 or higher, with build 18362 or higher.
    • Version 20H2.

Walkthrough

During this walkthrough, a stack is created from the template that you deploy. To avoid future costs, delete the stack after completing the walkthrough. For more information, see “Cleanup” later in this post.

Step 1: Configure a Linux environment on Windows 10

Configure Windows 10 and install Ubuntu 20.04

  1. Open Windows PowerShell as an administrator.
  2. Run the following command to enable WSL 2.

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

  1. Run one of the following commands to enable the Windows 10 Virtual Machine Platform.
    • For Windows 10 version 20H2:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

    • For Windows 10 versions 1903 or 1909:

Enable-WindowsOptionalFeature -Online -FeatureName VirutalMachinePlatform -NoRestart

  1. Restart your computer.
  2. Open Windows PowerShell as an administrator.
  3. Set WSL 2 as the default version.

wsl --set-default-version 2

  1. Restart your computer.
  2. Install Ubuntu 20.04 LTS from the Microsoft app store. Enter a UNIX user name and password when prompted during installation.

Set up a Linux account to run and manage TaskCat jobs

  1. In an Ubuntu terminal window, run the following command. Replace <example> with a name of your choice.

$ sudo adduser <example>

  1. Enter the UNIX password you created previously.
  2. Enter a password for the TaskCat job user. Enter it again when prompted.
  3. Press Enter for Full Name, Room Number, Work Phone, Home Phone, and Other.
  4. Enter Y for Is this information correct?

Initialize a public SSH key to access GitHub

  1. In Ubuntu terminal, paste the following command to generate an SSH (Secure Shell) key. Replace your primary GitHub email address for <user@example.com>.

$ ssh-keygen -t rsa -b 4096 -C "<user@example.com>"

  1. Press Enter for Enter a file in which to save the key (/home/your_email/.ssh/id_rsa).
  2. Press Enter twice when prompted to create a passphrase. Do not create a passphrase.
  3. Copy the contents of id_rsa.pub to the clipboard.

$ clip.exe < ~/.ssh/id_rsa.pub

  1. Add the SSH key to your GitHub account. For more information, see Adding a new SSH key to your GitHub account.
  2. In the Ubuntu terminal, verify authentication by running the following command:

$ ssh -T git@github.com

  1. Open the SSH configuration file in the Vim editor.

$ vim .ssh/config

  1. Enter the following. Replace your Ubuntu user name for <example> in the last line.
Host github.com
     HostName github.com
     User git
     PreferredAuthentications publickey
     IdentityFile /home/&lt;example&gt;/.ssh/id_rsa
  1. Press Esc.
  2. Enter :wq and press Enter.

Install Python

In an Ubuntu terminal window, run the following commands to install Python.

Note: To install Python and Pyenv, you may need to disconnect from a corporate VPN first.

$ sudo apt-get update
$ sudo apt-get update -y
$ sudo apt-get install python
$ sudo apt-get install python3-pip

Install Pyenv

The installation in the previous step installs the default version 3.8.5 of Python. In this walkthrough, we use Python version 3.8.3. To install version 3.8.3, first install Pyenv, a Python runtime-management tool that lets you maintain multiple versions of Python.

  1. In an Ubuntu terminal window, install Pyenv prerequisites.

$ sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

  1. Install Pyenv.

$ curl https://pyenv.run | bash

  1. In the Vim editor, open the Bash shell script .bashrc.

$ vim ~/.bashrc

  1. To configure your shell’s environment for Pyenv, add the following code to the end of the file, before the last fi statement. The first block sets the load path for pyenv in the .bashrc file. The second runs pyenv when you start a Bash shell.
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

$(which python|grep pyenv > /dev/null 2>&1)
PYENV_TEST=$?
if [[ $PYENV_TEST -eq 1 ]]
then
                echo "initialising pyenv"
                        eval "$(pyenv init -)"
   fi
  1. Press Esc.
  2. Enter :wq and press Enter.
  3. Close the Ubuntu terminal window and open a new one.

Install Python 3.8.3

  1. Install Python 3.8.3.

$ pyenv install 3.8.3

  1. Set the default Python version to 3.8.3.

$ pyenv global 3.8.3

  1. Verify that Python version 3.8.3 is the default version.

$ pyenv versions

The current default version displays.

system
* 3.8.3 (set by /home/<user>/.pyenv/version)

  1. Upgrade pip packages.

$ python3 -m pip install --upgrade pip

  1. Install the testresources extension to python unittest, to allow declarative use of resources by test cases.

$ pip install testresources

Install and configure AWS CLI

  1. TaskCat uses AWS Command Line Interface (AWS CLI). Run the following command to install the AWS CLI.

$ sudo apt install awscli

  1. Configure your AWS CLI installation.

$ aws configure

  1. The AWS CLI prompts you for the following information. Replace the sample values in the example with your own values. For more information about access keys, see Access key ID and secret access key.

AWS Access Key ID [None]: <AKIAIOSFODNN7EXAMPLE>
AWS Secret Access Key [None]: <wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY>
Default region name [us-east-1]: <us-east-1>
Default output format [json]: <json>

Note: A misspelled Region prevents successful connection to your AWS account. Confirm that the Region is entered correctly by running cat $HOME/.aws/config.

  1. Test your AWS account connectivity.

$ aws sts get-caller-identity

The command returns the AWS access key ID (UserId), AWS account number (Account), and Amazon Resource Name (ARN) of your AWS account. In the following example output, your IAM user name displays in place of <example>.

{
“UserId”: “AKIAIOSFODNN7EXAMPLE”,
“Account”: “01234567890”,
“Arn”: “arn:aws:iam::01234567890:user/<example>”
}

You have now configured a Linux environment on Windows 10.

Step 2: Install Docker Desktop

  1. Download and install Docker Desktop for Windows.
  2. Install and configure the Docker Desktop WSL 2 backend.

Step 3: Install TaskCat and Python library for Docker Engine API

  1. Install TaskCat.

$ pip install taskcat

  1. Install the Python library for the Docker Engine API.

$ pip install docker

  1. Test the TaskCat installation.

$ taskcat test run

The TaskCat version displays.

TaskCat version

Figure 2: TaskCat version

Step 4: Test the installation

Clone the test repo

  1. In the Ubuntu terminal, change to the home directory.

$ cd $HOME

  1. Clone the quickstart-microsoft-rdgateway repository.

$ git clone ssh://github.com/aws-quickstart/quickstart-microsoft-rdgateway

  1. Change to the repository root directory.

$ cd $HOME/quickstart-microsoft-rdgateway

  1. Update the repository submodules.

$ git submodule update --init --recursive --progress

Configure TaskCat to use your key pair

  1. Open the Amazon EC2 console.
  2. In the navigation pane, choose Key Pairs. Note the name of the key pair to use to create the RD Gateway stack.
  3. Run the following, replacing <example> with your key pair name.

$ echo \
KeyPairName: <example>> $HOME/quickstart-microsoft-rdgateway/.taskcat_overrides.yml

  1. Open .taskcat.yml in the Vim editor.

$ vim .taskcat.yml

  1. Enter –overridden– for the KeyPairName parameter. This ensures that the deployment reads the key pair name from .taskcat_overrides.yml.

Specify a single deployment Region for the test

  1. TaskCat deploys templates into every Region listed in the regions section of .taskcat.yml. To reduce the time and cost of our test deployment, delete all Regions except for us-east-1.
.taskcat.yml

Figure 3: .taskcat.yml

Note: Remember to add Regions back to the regions section of .taskcat.yml to test your templates across multiple Regions.

  1. Press Esc.
  2. Enter :wq and press Enter.

Deploy the test templates with TaskCat

  1. Run TaskCat.

taskcat test run -lmk -t rdgwMaster

  1. Open the AWS CloudFormation console. On the Stacks page, the tCaT-quickstart-microsoft-rdgateway-rdgwMaster stack created by TaskCat displays. In the Status column, CREATE_COMPLETE indicates a successful test deployment. Stack creation takes about 30 minutes.
AWS CloudFormation console

Figure 4: AWS CloudFormation console

Now that TaskCat is installed and configured, you can repeat the walkthrough with your repositories to test AWS CloudFormation templates on Windows 10.

Cleanup

To avoid incurring future charges, delete the resources created by the walkthrough. Follow these steps:

  1. Open the AWS CloudFormation console.
  2. On the Stacks page, select the tCaT-quickstart-microsoft-rdgateway-rdgwMaster stack.
  3. Choose Delete.

Conclusion

In this post, we explained how to install TaskCat on Windows 10 using WSL 2. TaskCat automates CloudFormation template testing and removes resources that are created so you don’t accrue charges after a test. Although it’s not natively supported on Windows, you can use TaskCat to test your CloudFormation templates on Windows 10 using the process we’ve explained. We invite you to perform the walkthrough and incorporate TaskCat in your CloudFormation template development. Let us know your experiences using TaskCat configured on Windows 10 in the comments.

Ivan Bishop

Ivan Bishop

Ivan Bishop is a partner solutions architect on the AWS Integration and Automation team. He helps independent software vendors securely migrate their customers to AWS using prescribed, scalable techniques and tools. His background encompasses all facets of enterprise-data-center infrastructure, virtualization and cloud. Ivan has worked with verticals as diverse as finance, healthcare, physics research, government, oil, and semiconductor.

Andrew Gargana

Andrew Gargan

Andrew Gargan is a partner solutions architect on the AWS Integration and Automation team. He is a DevOps and automation enthusiast who works on infrastructure-as-code deployments that automate software and infrastructure installation. Andrew has over five years of experience in the DevOps space and over 15 years of programming experience. He has also worked in several industries, such as insurance and healthcare.