Skip to main content
Welcome — this lesson shows the correct, safe way to remove nested AWS CloudFormation stacks and the resources they created. The core principle is simple and important:
  • Always delete the parent (top-level) stack. Do not delete nested stacks individually. When you delete the parent, CloudFormation cascades deletion to its nested stacks and their resources unless you explicitly set retention policies.
Why this matters: manually deleting nested stacks can leave orphaned resources, break dependency ordering, and cause stack deletion failures. Steps to delete nested stacks safely
  1. Identify the parent (top-level) stack in the CloudFormation Stacks console — the stack that was created directly, not an AWS::CloudFormation::Stack resource inside another stack.
  2. Select the parent stack and choose Delete.
  3. Monitor the parent stack’s events. CloudFormation will start deleting nested stacks and the resources they own in the correct order.
  4. Refresh related service consoles (S3, EC2, etc.) to confirm resources are being removed.
  5. If you used a templates bucket to host nested-stack templates (for example, eden-kodekloud-lkjo-bkt-templates), empty it and then delete the bucket.
A screenshot of the AWS CloudFormation "Stacks" console showing three stacks (DemoStack and two nested stacks) listed with status "UPDATE_COMPLETE" and creation timestamps. The page header shows the US East (Ohio) region and control buttons like Delete, Update stack, and Create stack.
Important details about DeletionPolicy and UpdateReplacePolicy
  • Nested stacks and their resources are deleted by default when the parent stack is deleted.
  • To keep a nested stack or certain resources after deleting the parent, set DeletionPolicy: Retain on the nested-stack resource (or on specific resources).
  • UpdateReplacePolicy controls behavior for resource replacement scenarios.
Examples Minimal parent stack declaring two nested stacks:
Resources:
  S3Stack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://eden-kodekloud-lkjo-bkt-templates.s3.amazonaws.com/simple-s3.yaml

  EC2Stack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://eden-kodekloud-lkjo-bkt-templates.s3.amazonaws.com/simple-ec2.yaml
Make a nested stack retain its resources when the parent is deleted:
Resources:
  S3Stack:
    Type: AWS::CloudFormation::Stack
    DeletionPolicy: Retain
    Properties:
      TemplateURL: https://eden-kodekloud-lkjo-bkt-templates.s3.amazonaws.com/simple-s3.yaml
Quick reference: DeletionPolicy options
DeletionPolicy valueEffect
Delete (default)Resource (or nested stack) is deleted when its stack is deleted.
RetainResource is left intact; CloudFormation stops managing it.
SnapshotFor supported resources (e.g., RDS), a snapshot is taken before deletion.
Monitoring and verification
  • Watch stack events in the CloudFormation console to see nested stack deletion progress and any errors.
  • Check the service-specific consoles (S3, EC2, RDS, IAM, etc.) to confirm resources have been removed or retained according to policy.
  • If a nested stack fails to delete, review the nested stack’s events to find the resource causing the failure.
Warning: do not delete nested stacks individually
Avoid deleting nested stacks directly from the console or API. Removing only the child stack may break the parent stack’s state and lead to orphaned resources or failed operations. Always delete the parent stack unless you intentionally used DeletionPolicy: Retain.
Cleaning up the templates bucket (S3) If you used an S3 bucket to store nested stack templates (for example, eden-kodekloud-lkjo-bkt-templates), remove it after all nested-stack resources are cleaned up.
  • To delete a non-empty bucket you must first empty it.
    • In the S3 console, select the bucket and choose Empty.
    • Confirm by typing the required confirmation phrase (for example, “permanently delete”) and proceed.
A screenshot of the AWS S3 console showing a confirmation dialog to permanently delete all objects in the bucket "eden-kodekloud-lkjo-bkt-templates," with an input field requiring you to type "permanently delete" and buttons to Cancel or Empty. A blue banner above suggests using a lifecycle rule to more efficiently empty large buckets.
  • Once the bucket is empty, delete the bucket itself. The console will prompt you to type the bucket name to confirm deletion.
Screenshot of the AWS S3 console showing a "Delete bucket" confirmation for the bucket "eden-kodekloud-lkjo-bkt-templates," asking the user to type the bucket name to confirm deletion. The dialog shows an input field and a disabled "Delete bucket" button with a "Cancel" link.
Example S3 bucket resource used in child templates:
Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties:
      Tags:
        - Key: Developer
          Value: John
Best practices and checklist
  • Delete the parent stack to remove nested stacks and their resources in the correct order.
  • Use DeletionPolicy or UpdateReplacePolicy when you need to preserve resources.
  • Verify deletions in both CloudFormation and the individual AWS service consoles.
  • Empty and delete any auxiliary S3 templates buckets after cleanup.
  • Automate cleanup with scripts or CI/CD steps when possible to avoid manual mistakes.
Best practice: delete the parent stack to remove nested stacks and their resources. Use DeletionPolicy and UpdateReplacePolicy to intentionally retain child stacks or resources during delete/replace operations. For more, see the AWS CloudFormation documentation on nested stacks and deletion policies.
References That completes the cleanup: parent stack deleted, nested stacks removed (or retained if specified), resources terminated or preserved per policy, and the templates bucket emptied and deleted.

Watch Video