Using CloudFormation Drift Detection

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

This lab discusses CloudFormation drift detection. CloudFormation stack drift occurs when the resources in a stack have drifted from their original creation template. This can become a major problem — and drift detection can be used to identify it. After the problem is identified, the lab covers the stack update steps that can be taken to bring the CloudFormation stack back into sync with the original template.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create CloudFormation Stack
  1. In EC2, create a key pair called driftlab.
  2. Create a CloudFormation stack using the ec24drift.json template file linked in the lab instructions. Use the following stack details:
    • Stack name: driftlab
    • InstanceType: t2.micro
    • KeyName: driftlab
    • MySubnet: Select any one of the listed subnets
    • myVPC: Select the only listed VPC
    • Give the stack a "name" tag of "driftlab"
Terminate an EC2 Instance to Introduce Stack Drift
  1. In EC2, select Instance3, and under Actions > Security > Change security groups, remove the currently selected security group, and add the default security group.
  2. Select Instance 1, and terminate the instance.
  3. Go to Networking & Security > Security Groups. For the security group with driftlab-InstanceSecurityGroup in the name, add HTTP and HTTPS inbound rules.
  4. In S3, disable static website hosting for the bucket that was created (it will have driftlab in the name).
  5. In CloudFormation, detect drift and view the results.
Eliminate Drift from Stack
  1. In EC2, select Instance3. Under Actions > Security > Change security groups, remove the default security group, and reassign the driftlab- security group.
  2. In CloudFormation, select EC2Instance3, detect drift, and view the results for the resource to see that it is now in sync.
  3. Still in CloudFormation, update the driftlab stack by uploading the afterdriftupdate.json file (link available in the lab instructions) as the template file.
  4. Detect drift and view the results to see that all resources are in sync.

Additional Resources

Note: Minor updates were made to the UI since this lab was recorded. Refer to the steps in the lab guide for the most up-to-date instructions.

Log in to the AWS environment using the cloud_user credentials provided.

Once inside the AWS account, make sure you are in the us-east-1 (N. Virginia) region.

There are 2 CloudFormation templates for this lab:

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?