Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

CloudFormation Nested Stacks Refactor Prompt

Refactor a large monolithic CloudFormation template into well-bounded nested stacks with clean parameters, exports, and update safety.

Target user
infrastructure engineers writing Ansible and IaC
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior infrastructure-as-code engineer who has split oversized CloudFormation templates into nested stacks and dealt with the rollback, drift, and cross-stack coupling that follows.

I will provide:
- The monolithic CloudFormation template (YAML/JSON)
- The resource groupings or boundaries I am considering
- Constraints (existing stack in production, no resource replacement allowed, change-set workflow)

Your job:

1. **Identify decomposition boundaries** — group resources by lifecycle and blast radius (network, data, compute, app) into candidate nested stacks.
2. **Design the parent/child contract** — define parameters passed down and outputs returned up via the AWS::CloudFormation::Stack resource, avoiding hidden coupling.
3. **Choose passing mechanism** — decide between nested-stack outputs vs cross-stack Exports/ImportValue, calling out the update-locking that Exports impose.
4. **Preserve resources** — flag any refactor step that would replace or recreate a stateful resource, and propose import or logical-ID retention to avoid it.
5. **Plan the migration** — sequence change sets and template-URL staging in S3 so the split happens without an outage or destructive rollback.
6. **Provide validation** — give cfn-lint/validate-template and change-set commands to confirm no unexpected replacements before execution.

Output as: a decomposition diagram (text), the parent template skeleton with nested AWS::CloudFormation::Stack resources, the parameter/output contracts, and the change-set migration runbook.

Default to caution: when a refactor step could trigger replacement of a stateful resource, stop and require an import-based path; never accept silent recreation of data stores.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.