Skip to main content

Disaster Recovery Preparedness with AWS CloudFormation

Hands-On Lab

 

Photo of

Training Architect

Length

00:30:00

Difficulty

Intermediate

Welcome to this live AWS learning activity where we will be using CloudFormation to launch the infrastructure for a highly-available WordPress blog. The services that will be deployed include: 1) A VPC with 4 subnets and an internet gateway 2) A NAT Gateway, route tables, security groups, and NACLs 3) A bastion host 4) An application load balancer 5) Web server instances in an Auto Scaling group CloudFormation is the AWS solution for infrastructure as code. We can design and deploy applications using templates written in the YAML or JSON format. This allows for version controlling infrastructure as if it were code. CloudFormation is especially useful in disaster recovery and migration scenarios. Good luck and enjoy the Learning Activity!

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.

Disaster Recovery Preparedness with AWS CloudFormation

Introduction

CloudFormation is the AWS solution for infrastructure as code. We can use it to design and deploy applications using templates written in the YAML or JSON format. This allows for version controlling infrastructure as if it were code, which is especially useful for disaster recovery and migrations.

In this hands-on lab, we will use CloudFormation to launch the infrastructure for a highly available WordPress blog. We will use a CloudFormation template to automate the process of deploying the following architecture:

  • A VPC with 4 subnets and an internet gateway
  • A NAT gateway, route tables, security groups, and NACLs
  • A bastion host
  • An application load balancer
  • Web server instances in an Auto Scaling group

Let's get started. Log in to the AWS Management Console using the credentials provided on the lab instructions page.

Deploying the App

Once you've logged in to the AWS console, navigate to the S3 service. You can find it under the Storage header on the AWS services page or by opening the Services dropdown menu. On the Amazon S3 page, click the name of the S3 bucket to open it.

There are two files in the S3 bucket: a JSON file and a YAML file. These are CloudFormation infrastructure templates (they are actually the same template, just in two different formats). Click on one of them, and copy the link at the bottom of the page.

Now we need to create a key to connect to our EC2 instances. Open the EC2 service in a new browser tab. Select Key Pairs in the left sidebar, and then click Create Key Pair. For Key pair name, type "cfkey". Then click Create. If prompted, accept the download.

Next, open the CloudFormation dashboard by navigating to CloudFormation in the Services menu. Click Create Stack. On the Select Template page, choose the Specify an Amazon S3 template URL option, and paste the link we copied earlier into the text field. Click Next.

On the Specify Details page, type "blog" for Stack name. Under Parameters, click into the text field next to WebServerKeyName, and select cfkey from the dropdown. Click Next. Leave all of the settings on the Options page as they are, and click Next. Then click Create. Our stack is now creating. It may take a few minutes for the status to change from CREATE_IN_PROGRESS to CREATE_COMPLETE.

In the meantime, navigate to the VPC service in the AWS Management Console. Clicking through the different headers of this menu, we can see that all of the resources included in our template have been created. This means that our template test was a success. We don't want to leave these resources running, so the next step is to delete the stack. But we're going to leave the template files in the S3 bucket so we can quickly deploy these resources again in the future in the event of a primary application failure.

Deleting the Stack

Go back to your CloudFormation tab, and select the blog stack by checking the checkbox on the left. Click the Actions button, and select Delete Stack from the dropdown menu. Then click Yes, Delete.

This will begin the process of deleting the stack resource by resource. Open the Events tab at the bottom of the screen to monitor the deletion process. Once the deletion process is complete, the blog stack will disappear from the stack list.

Conclusion

Congratulations, you've successfully completed this lab!