Install AWS CloudFormation Helper Script on CentOS 8 | RHEL 8

The
You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off
The

The
The

AWS CloudFormation is a service that helps you automatically configure and manage resources on AWS Cloud Platform. CloudFormation uses templates to build applications or services in order to use “Stack“.

AWS CloudFormation provides the following Python helper scripts that can be used to install software and start services on Amazon EC2 instances created as part of the stack:

  • cfn-init: Used to retrieve and interpret resource metadata, install software packages, create files, and start services.
  • cfn signal: Used to signal with CreationPolicy or WaitCondition, so that when the necessary resources or applications are ready, you can synchronize other resources in the stack.
  • cfn-get-metadata: The path used to retrieve the metadata or specific key of the resource.
  • cfn-hup: Used to check metadata updates and execute custom hooks when changes are detected.

Install AWS CloudFormation Helper Script on CentOS 8 | RHEL 8

When using non-Amazon Linux on AWS OS templates, please install aws-cfn-bootstrap The package cannot be completed from the repository because it only works with Amazon Linux. On the Amazon Linux AMI, the AWS CloudFormation helper script is pre-installed on /opt/aws/bin. We will discuss how to install the CloudFormation Helper script on CentOS 8 at once. RHEL 8.

Step 1: Install Python2 on CentOS 8 | RHEL 8

From previous tests, I was unable to install the CloudFormation Helper script using Python 3. I must install Python 2.

sudo dnf -y update
sudo dnf -y install python2

If you want to set Python2 as the default version of Python, use the following command:

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

Confirm the python command version output:

$ python -V
Python 2.7.16

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

After installing Python2, download the latest aws-cfn-bootstrap file.

curl -O https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz

Extracting files.

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

Install the Python script.

cd aws-cfn-bootstrap-*/
sudo python2 setup.py build
sudo python2 setup.py install

Create symbolic links for initialization and scripting:

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

confirm:

$ 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

of CodeDeploy agent It is a software package that can be used in CodeDeploy deployment after installation and configuration on the instance.

Install the 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 the 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 the AWS CodeDeploy agent on CentOS 8. RHEL 8:

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

When prompted, please accept the installation:

Dependencies resolved.
========================================================================================================================================================
 Package                                  Architecture                   Version                             Repository                            Size
========================================================================================================================================================
Installing:
 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 

Installed:
  codedeploy-agent-1.0-1.1597.noarch                                                                                                                    

Complete!

Now you can create an AMI from an instance configured for any CloudFormation automation job.

Similar guidelines:

Create AWS IAM users and groups using the AWS CLI

How to rename IAM username on AWS

AWS courses to check:


AWS CloudFormation-Introductory Course

★★★☆☆
(317)

$ 13.50

$ 84.36

In stock

Buy now

Install AWS CloudFormation Helper Script on CentOS 8 | RHEL 8Udemy.com


AWS CloudFormation-Simplify|Use YAML

AWS CloudFormation-Simplify|Use YAML

★★★★★
(321)

$ 13.50

$ 22.49

In stock

Buy now

Install AWS CloudFormation Helper Script on CentOS 8 | RHEL 8Udemy.com

You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off
The

The
The

Sidebar