CloudFormation Helper Scripts
AWS Training Architect II in Content
Welcome to this hands-on AWS Learning Activity in which you will learn how to utilize Helper Scripts to help manage the provisioning of EC2 instances both individually and in Auto Scaling Groups. 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.
CloudFormation Helper Scripts
In this lab, we will learn how to utilize helper scripts to provision individual EC2 instances and Auto Scaling groups. AWS CloudFormation provides the following Python helper scripts that we can use to install software and start services on Amazon EC2 instances:
cfn-initâ Used to retrieve and interpret resource metadata, install packages, create files, and start services.
cfn-signalâ Used 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â Used to retrieve metadata for a resource or path to a specific key.
cfn-hupâ Used to check for updates to metadata and execute custom hooks when changes are detected.
In this lab, we're going to use CloudFormation helper scripts to install a LAMP stack on an EC2 instance.
Log in to the AWS Management Console using the credentials provided on the lab instructions page.
Once you're logged in to the AWS account, make sure you are using us-east-1 (N. Virginia) as the selected region.
Note: You can download the CloudFormation Template for this lab here.
Create a Key Pair
- In the AWS Management Console dashboard, navigate to the EC2 service.
- In the left sidebar, click Key Pairs, then click Create a Key Pair.
- Name the key pair "helperdemo". Then, click Create.
Create a CloudFormation Stack
- Open the provided CloudFormation Template file, and copy the contents.
- Next, navigate to the CloudFormation service in the AWS Management Console.
- Click Design template.
- Click the Template tab at the bottom of the page, and paste in the contents of the CloudFormation Template file we just copied (make sure the JSON option is selected for the template language).
- Click the checkmark icon at the top of the page to validate.
- Then, click the cloud arrow icon at the top of the page to create a new stack.
- Leave all of the default settings on the Select Template page, and click Next.
- On the Specify Details page, name the stack "HelperDemo".
- Enter any valid username and password for MySQL in the parameters section.
- For KeyName, select helperdemo from the dropdown.
- Click Next, then click Next again on the Options page.
- Click Create.
- Refresh the page, and select the HelperDemo stack from the list.
- Scroll through the Events tab at the bottom of the screen to monitor the stack creation process.
- Click the Events tab, and change it to Outputs.
- Right-click the URL next to WebsiteURL, and open the link in a new tab.
Congratulations, you've successfully completed this lab!