Introduction to quickstart-linux-utilities
To properly signal AWS CloudFormation during bootstrapping, CloudFormation requires some functions (
qs_aws-cfn-bootstrap) to be installed on your Linux Amazon EC2 instances. The bootstrap helper scripts,
cfn-init, assist with common operations like package installation, service management, CloudFormation signaling, and metadata retrieval. Such tools allow you to standardize your installation and reduce maintenance overhead. The code I provide in this post allows you to easily invoke the latest version of this utility at stack launch. Note that AWS conveniently provides a Linux distribution called Amazon Linux, which has this utility built-in.
Quick Start Linux utilities provide a simple and easy way to automate the installation of AWS CloudFormation tools across common Linux distributions. Examples include the Red Hat OpenShift, Corda Blockchain, and HashiCorp Consul Quick Starts. Depending on which distribution is running your Amazon EC2 instance, use package managers, such as
zypper, to install the
aws-cfn-bootstrap tools. This can be accomplished by running the OS-specific install commands via UserData. Note that installing these tools requires dependency handling to be part of your code, which can bloat your UserData. After installing this utility, you can call wrapper commands, such as
qs_aws-cfn-bootstrap, that install the prerequisite Python pip (if needed) before installing
If you plan to support different Linux distributions in your CloudFormation template, additional logic is needed, but the extra logic will also bulk up your UserData. This blog post details an approach of using
quickstart-linux-utilities to offload tedious tasks and keep your UserData streamlined.
This utility supports the following Linux distributions.
- Amazon Linux
- CentOS 7
- Red Hat Enterprise Linux 7
- Ubuntu (16.04)
- Ubuntu (18.04)—coming soon
How to make quickstart-linux-utils available in UserData
Git-based method (recommended)
Depending on your OS, you may need to replace
zypper. Alternatively, you can use
wget to pull the files directly from GitHub using the raw URL. If you forked the repo update, the following commands will invoke your forked URLs.
- Red Hat
Clone the source
Loading the utility in UserData
To make the
qs utilities available during bootstrapping, load the main script,
quickstart-cfn-tools.source. When the tool is loaded, it simply runs
qs_aws-cfn-bootstrap to install the AWS CloudFormation helper.
qs_aws-cfn-bootstrap function determines the OS type and then issues the following commands.
- Install Python and its dependencies.
- Install pip and its dependencies.
- Install cfn-init.
The following section includes code snippets that can be cut and pasted into the UserData section on any supported Linux distribution.
qs_update-osupdates the OS with the latest patches.
qs_bootstrap_pipinstalls Python and pip.
qs_get-python-path, which are commands that can be called during other bootstrapping tasks.
When it’s complete,
cfn-hup become available for use in UserData. For more information on cfn helper scripts, see CloudFormation helper scripts.
Here are some examples of
quickstart-linux-utilities that have been implemented.
Contribution and Support
If you want to report bugs or contribute support for other operating systems, you can use the repo issues register.
quickstart-linux-utilities reduces development time when implementing UserData scripts via CloudFormation templates. Additionally, it provides consistency and maintainability by providing a single location where these helper utilities can be patched and enhanced as needed.