CloudFormation Helper Scripts

Hands-On Lab

 

Photo of Craig Arcuri

Craig Arcuri

AWS Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

CloudFormation Helper Scripts

Introduction

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

  1. In the AWS Management Console dashboard, navigate to the EC2 service.
  2. In the left sidebar, click Key Pairs, then click Create a Key Pair.
  3. Name the key pair "helperdemo". Then, click Create.

Create a CloudFormation Stack

  1. Open the provided CloudFormation Template file, and copy the contents.
  2. Next, navigate to the CloudFormation service in the AWS Management Console.
  3. Click Design template.
  4. 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).
  5. Click the checkmark icon at the top of the page to validate.
  6. Then, click the cloud arrow icon at the top of the page to create a new stack.
  7. Leave all of the default settings on the Select Template page, and click Next.
  8. On the Specify Details page, name the stack "HelperDemo".
  9. Enter the password from MySQL for DBPassword and DBRootPassword.
  10. For KeyName, select helperdemo from the dropdown.
  11. Click Next, then click Next again on the Options page.
  12. Click Create.
  13. Refresh the page, and select the HelperDemo stack from the list.
  14. Scroll through the Events tab at the bottom of the screen to monitor the stack creation process.
  15. Click the Events tab, and change it to Outputs.
  16. Right-click the URL next to WebsiteURL, and open the link in a new tab.

Conclusion

Congratulations, you've successfully completed this lab!