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
- In EC2, create a key pair called
driftlab
. - 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"
- In EC2, create a key pair called
- Terminate an EC2 Instance to Introduce Stack Drift
- In EC2, select Instance3, and under Actions > Security > Change security groups, remove the currently selected security group, and add the default security group.
- Select Instance 1, and terminate the instance.
- Go to Networking & Security > Security Groups. For the security group with
driftlab-InstanceSecurityGroup
in the name, add HTTP and HTTPS inbound rules. - In S3, disable static website hosting for the bucket that was created (it will have
driftlab
in the name). - In CloudFormation, detect drift and view the results.
- Eliminate Drift from Stack
- In EC2, select Instance3. Under Actions > Security > Change security groups, remove the default security group, and reassign the driftlab- security group.
- In CloudFormation, select EC2Instance3, detect drift, and view the results for the resource to see that it is now in sync.
- Still in CloudFormation, update the driftlab stack by uploading the
afterdriftupdate.json
file (link available in the lab instructions) as the template file. - Detect drift and view the results to see that all resources are in sync.