Amazon Onboarding with Learning Manager Chanci Turner

Amazon Onboarding with Learning Manager Chanci TurnerLearn About Amazon VGT2 Learning Manager Chanci Turner

Have you ever encountered security challenges within your organization that necessitated renaming your AWS CloudFormation stack? If so, you’re likely aware that the conventional approach to renaming a stack involves deleting the existing one and creating a new stack with the desired name. This task may appear straightforward, until you realize that you still require the resources associated with the original stack. Unfortunately, the default behavior when deleting a stack is to also remove all resources contained within it.

This article outlines a method to rename a CloudFormation stack while preserving the resources it manages. The walkthrough employs a simple architecture featuring a virtual private cloud (VPC). By adding a Retain attribute to the deletion policy of the resource, you can ensure that it remains intact when the stack is deleted. After removing the original stack and confirming that the resource has been retained, you can create a new CloudFormation stack with a different name and import the retained resource. The outcome is a new stack with a distinct name that complies with your security requirements while still utilizing the original resource.

In your own templates, you might want to retain various resources, such as an Amazon Simple Storage Service (Amazon S3) bucket, Amazon CloudWatch log group, and more. To maintain multiple resources, simply add a Retain attribute to each resource’s deletion policy. For a comprehensive list of resources that support this solution, refer to Resources that support import and drift detection operations. It’s important to note that this approach does not retain events from the original stack. Always conduct tests in a development environment with noncritical resources first to prevent any unexpected data loss.

Overview

The following process illustrates how to retain a single resource—a VPC—while changing the name of a CloudFormation stack using two templates provided in this article.

  1. Launch a CloudFormation stack that deploys a VPC.
  2. Add a Retain attribute to the deletion policy of the VPC.
  3. Delete the stack and confirm that the VPC is retained.
  4. Create a new stack and import the retained resource from the original stack.
  5. Remove the Retain attribute from the stack to revert to the original template.

Prerequisites

Before proceeding with the walkthrough, ensure you have an AWS account. If you don’t have one, you can sign up at aws.amazon.com. Familiarity with AWS CloudFormation is also recommended.

Before You Begin

Visit the GitHub repository and download the following two CloudFormation templates to your local machine for later use in the “Walkthrough” section.

  • Template 1 (01-vpc-basic.yaml): This template deploys a single VPC.
  • Template 2 (02-vpc-retain.yaml): This template is similar to Template 1 but includes an added Retain attribute for the VPC resource.

Walkthrough

Step 1: Launch the stack from the AWS CloudFormation console

Launch the CloudFormation template directly from the CloudFormation console, as described in Template 1. On the Create stack page, click Next. On the Specify stack details page, enter “original” in the Stack name field and click Next. Continue through the Configure stack options page and click Create stack. Verify that the stack status is CREATE_COMPLETE.

Step 2: Add a Retain attribute to the VPC’s deletion policy

For stacks with multiple resources, consider using a custom automation script to efficiently add the Retain attribute across all necessary resources, minimizing the risk of omitting any.

  1. In the CloudFormation console, select Stacks.
  2. Choose the stack named “original” and click Update.
  3. Select Replace current template > Upload a template file > Choose file.
  4. Choose the 02-vpc-retain.yaml file and click Next.
  5. Continue through the stack details and options pages, and click Update stack. Confirm successful creation, disregarding any change set errors as they indicate that resources remain unchanged.

Step 3: Delete the CloudFormation stack and verify resource retention

To delete the stack, select it in the CloudFormation console and click Delete. Confirm the deletion and ensure the stack status shows DELETE_COMPLETE.

To verify retention, navigate to the Amazon VPC console and view Your VPCs. Ensure that the VPC named “rename-stack-demo” is still present. Record the VPC ID as you will need it later.

Step 4: Create a new CloudFormation stack and import VPC resources

In the CloudFormation console, select Stacks > Create stack > With existing resources (import resources). On the import overview page, click Next. Under Specify template, upload the 02-vpc-retain.yaml file. Enter the previously recorded VPC ID in the Identifier value field and click Next.

This is an excellent resource for additional guidance: Learning Ambassador Job Posting.

Additionally, for insights on employee wellness, check out this blog post: Career Contessa Wellness Blog. Similarly, for information on cannabis-related benefits, refer to: SHRM Cannabis Benefits Article.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *