AWS CloudFormation is a service that helps you automate provisioning and management of resources on AWS Cloud platform. CloudFormation uses templates to architect application or service for quick and reliable provisioning using “stacks”.

AWS CloudFormation provides the following Python helper scripts that you can use to install software and start services on an Amazon EC2 instance that you create as part of your stack:

  • cfn-init: Use to retrieve and interpret resource metadata, install packages, create files, and start services.
  • cfn-signal: Use to signal with a CreationPolicy or WaitCondition, so you can synchronize other resources in the stack when the prerequisite resource or application is ready.
  • cfn-get-metadata: Use to retrieve metadata for a resource or path to a specific key.
  • cfn-hup: Use to check for updates to metadata and execute custom hooks when changes are detected.

Install AWS CloudFormation Helper Scripts on CentOS 8 | RHEL 8

When working with OS templates other than Amazon Linux on AWS, installation of aws-cfn-bootstrap package cannot be done from a repository since it is only available for Amazon Linux. On Amazon Linux AMI, the AWS CloudFormation helper scripts are preinstalled in /opt/aws/bin. We will explore how once can install CloudFormation Helper Scripts on CentOS 8 | RHEL 8.

Step 1: Install Python2 on CentOS 8 | RHEL 8

From my previous testing, I was not able to install CloudFormation Helper Scripts with Python 3. I had to install Python 2.

sudo dnf -y update
sudo dnf -y install python2

If you want to make Python2 the default version of Python, use the command:

sudo alternatives --set python /usr/bin/python2

Confirm python command version output:

$ python -V
Python 2.7.16

Step 2: Install CloudFormation Helper Scripts on CentOS 8 | RHEL 8

Once Python2 has been installed, download the latest aws-cfn-bootstrap file.

curl -O

Extract file.

tar xvf aws-cfn-bootstrap-latest.tar.gz

Install Python scripts.

cd aws-cfn-bootstrap-*/
sudo python2 build
sudo python2 install

Create symbolic links for init and scripts:

sudo mkdir -p /opt/aws/bin
sudo ln -s /usr/init/redhat/cfn-hup /etc/init.d/cfn-hup
sudo chmod 775 /usr/init/redhat/cfn-hup
sudo ln -s /usr/bin/cfn-hup /opt/aws/bin/cfn-hup
sudo ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal
sudo ln -s /usr/bin/cfn-init /opt/aws/bin/cfn-init
sudo ln -s /usr/bin/cfn-get-metadata /opt/aws/bin/cfn-get-metadata
sudo ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal
sudo ln -s /usr/bin/cfn-send-cmd-event /opt/aws/bin/cfn-send-cmd-event
sudo ln -s /usr/bin/cfn-send-cmd-result /opt/aws/bin/cfn-send-cmd-result


$ ls -lh /opt/aws/bin/
total 0
lrwxrwxrwx. 1 root root 25 Jun  4 13:28 cfn-get-metadata -> /usr/bin/cfn-get-metadata
lrwxrwxrwx. 1 root root 16 Jun  4 13:27 cfn-hup -> /usr/bin/cfn-hup
lrwxrwxrwx. 1 root root 17 Jun  4 13:28 cfn-init -> /usr/bin/cfn-init
lrwxrwxrwx. 1 root root 27 Jun  4 13:28 cfn-send-cmd-event -> /usr/bin/cfn-send-cmd-event
lrwxrwxrwx. 1 root root 28 Jun  4 13:28 cfn-send-cmd-result -> /usr/bin/cfn-send-cmd-result
lrwxrwxrwx. 1 root root 19 Jun  4 13:28 cfn-signal -> /usr/bin/cfn-signal

Step 3: Install AWS CodeDeploy Agent on CentOS 8 | RHEL 8

The CodeDeploy agent is a software package that, when installed and configured on an instance, makes it possible for that instance to be used in CodeDeploy deployments.

Install AWS CLI:

sudo pip3 install awscli

Configure it with credentials:

$ aws configure
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]:

Download codedeploy agent rpm file.

$ aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' .
download: s3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm to ./codedeploy-agent.noarch.rpm

Install Ruby on RHEL 8 | CentOS 8:

sudo dnf -y install @ruby

Finally install AWS CodeDeploy Agent on CentOS 8 | RHEL 8:

sudo dnf install ./codedeploy-agent.noarch.rpm

Accept installation when you get a prompt:

Dependencies resolved.
 Package                                  Architecture                   Version                             Repository                            Size
 codedeploy-agent                         noarch                         1.0-1.1597                          @commandline                         3.3 M

Transaction Summary
Install  1 Package

Total size: 3.3 M
Installed size: 17 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                1/1 
  Running scriptlet: codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
pre hook : 1
Checking the ruby version.
Checking if there is already a process named codedeploy-agent running.

  Installing       : codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
  Running scriptlet: codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
post hook : 1
Check if there is a codedeployagent config file.
Start codedeploy-agent in post hook if this is a first install.
Installing codedeploy-agent auto-update cron in '/etc/cron.d/codedeploy-agent-update'...
Installing codedeploy-agent auto-update cron in '/etc/cron.d/codedeploy-agent-update'...Complete

  Verifying        : codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 



You can now create an AMI from the instance configured for any CloudFormation automation works.

Similar guides:

Create AWS IAM Users & Groups with AWS CLI

How To Rename IAM User name on AWS

AWS Courses to check:

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here