How can I install CloudFormation helper scripts on Ubuntu 16.04 LTS/Ubuntu 18.04 LTS/Ubuntu 20.04 LTS/Ubuntu 22.04 LTS or RHEL 9 AMIs?

2 minute read
1

I want to install AWS CloudFormation helper scripts on Ubuntu 16.04 LTS, Ubuntu 18.04 LTS, Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, and RHEL 9 Amazon Machine Images (AMIs).

Short description

You must install helper scripts for Ubuntu 16.04 LTS, Ubuntu 18.04 LTS, Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, and RHEL 9 AMIs during the boot process. Use the UserData property to download and install the AMIs. Then, start the cfn-hup service at launch. To get the latest binaries of the aws-cfn-bootstrap package, see CloudFormation helper scripts reference.

Resolution

1.    Review the templates for Ubuntu 16.04 LTS script, Ubuntu 18.04 LTS script, Ubuntu 20.04 LTS script, Ubuntu 22.04 LTS script, on RHEL 9 script on GitHub. These scripts create a service in systemd to allow the cfn-hup helper daemon to automatically start at boot.
Important: Make systemd a dependency of an existing boot target. Use multi-user.target to create the dependency.

2.    Review how to define the UserData property of the instance.

3.    Create the cfn-hup configuration file, cfn-hup hook, and systemd file for cfn-hup /lib/systemd/systemcfn-hup.service. Refer to the instructions that are set in the files key.

4.    To activate the service in systemd and start the service, use the commands key.

5.    To confirm that the cfn-hup service starts after it launches the stack, run the following command:

systemctl status cfn-hup

If cfn-hup starts successfully, then you receive an output that's similar to the following one:

cfn-hup.service - cfn-hup daemon
   Loaded: loaded (/usr/lib/systemd/system/cfn-hup.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-10-12 08:10:26 EDT; 1min 11s ago
 Main
PID: 4852 (cfn-hup)
   CGroup: /system.slice/cfn-hup.service            
           └─4852 /usr/bin/python /opt/aws/bin/cfn-hup
Oct 12 08:10:26 ip-172-31-44-180.ec2.internal systemd[1]: Started cfn-hup daemon. 
Oct 12 08:10:26 ip-172-31-44-180.ec2.internal systemd[1]: Starting cfn-hup daemon...

Note: If you use systemd, then the cfn-init helper script doesn't support the services key. Instead, use the commands key as shown in the previous example.


Related information

CFNhelpernonAMZNAMIs (GitHub)

AWS OFFICIAL
AWS OFFICIALUpdated a year ago