Updating CloudFormation Stacks with Direct Updates and Change Sets

Hands-On Lab

 

Photo of Craig Arcuri

Craig Arcuri

AWS Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on lab, we will walk through proper ways to update CloudFormation stacks. We will first update a stack with direct updates, and then use change sets to update a stack. In the process, we will create multiple change sets and view the behavior of the stack when a change set is applied.

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.

Updating CloudFormation Stacks with Direct Updates and Change Sets

Introduction

In this hands-on lab, we will walk through proper ways to update CloudFormation stacks. We will first update a stack with direct updates, and then use change sets to update a stack. In the process, we will create multiple change sets and view the behavior of the stack when a change set is applied.

Solution

Log in to the AWS environment using the credentials provided. Make sure you are using us-east-1 (N. Virginia) as the selected region.

The lab uses two CloudFormation templates, which you can download at the lab GitHub repository.

Deploy a LAMP Stack Using an AWS CloudFormation Template

  1. Navigate to CloudFormation.
  2. Click Create stack.
  3. In the Prerequisite - Prepare template section, select Create template in Designer.
  4. Click Create template in designer.
  5. Click the Template tab at the bottom.
  6. Copy everything in the LampStack.json file (from the lab GitHub), and paste it into the Template window.
  7. In a new browser tab, navigate to EC2 > Key Pairs.
  8. Click Create Key Pair.
  9. Give it a key pair name of "updatekp", and click Create.
  10. Click Security Groups in the left-hand menu.
  11. Copy the security group ID and paste it into a text file, since we'll need it in a minute.
  12. Navigate to VPC > Subnets.
  13. Select one of the listed subnets, and copy its subnet ID. Paste it into a text file, since we'll also need it soon.
  14. Back in the CloudFormation template window, click the cloud icon with the up arrow to create the stack.
  15. Click Next.
  16. On the stack details page, set the following values:
    • Stack name: stackforUpdate
    • DBPassword: Your choice
    • DBRootPassword: Your choice
    • DBUser: Your choice
    • InstanceType: t2.micro
    • KeyName: tempanatomy
    • MySG: Paste in the security group ID you copied earlier
    • MySubnet: Paste in the subnet ID you copied earlier
  17. Click Next.
  18. Leave the defaults on the stack options page, and click Next.
  19. Click Create stack. It will take a few minutes for it to fully be created.

Update the LAMP Stack

Perform a Direct Update

  1. Click Update.
  2. Select Use current template, and click Next.
  3. Change the InstanceType to t2.small.
  4. Click Next.
  5. Leave the defaults on the stack options page, and click Next.
  6. Click Update stack.

Perform an Update with Change Sets

First Change Set

  1. On the stacks dashboard, click Stack actions > Create change set for current stack.
  2. Select Edit template in designer, and click View in Designer.
  3. Copy everything in the changeset.json file (from the lab GitHub), and paste it into the Template window within the template after the original WebServerInstance section of the template (above the Outputs section).
  4. Click Next.
  5. Un-check Use existing value for the DBPassword and DBRootPassword to reset them as well.
  6. Click Next.
  7. On the stack options page, set the Key as "name" and Value as "changeset".
  8. Click Next.
  9. Click Create change set.
  10. In the dialog, enter a change set description of "first change set", and click Create change set.
  11. On the stacks dashboard, click Stack actions > Create change set for current stack.

Second Change Set

  1. Select Use current template, and click Next.
  2. Change the DBName to "ChangeSetDemo".
  3. Click Next.
  4. Leave the defaults on the stack options page, and click Next.
  5. Click Create change set.
  6. In the dialog, enter a change set description of "Changed DB name", and click Create change set.
  7. Select our first change set.
  8. Click Execute.
  9. In a new browser tab, navigate to EC2 > Instances. We should see a second web server is initializing.

Third Change Set

  1. Back in the CloudFormation browser tab, click Create change set.
  2. Select Use current template, and click Next.
  3. Change the DBName to "changemyname".
  4. Click Next.
  5. Leave the defaults on the stack options page, and click Next.
  6. Click Create change set.
  7. In the dialog, enter a change set description of "ChangeDBName", and click Create change set.
  8. Click Execute.

Conclusion

Congratulations on successfully completing this hands-on lab!