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
-
AWS CDK Escape Hatches & L1 Override Prompt
Use CDK escape hatches (addPropertyOverride, addOverride, addDeletionOverride, and L2-to-L1 access) to set properties the L2 construct does not expose, without forking constructs or dropping to raw CloudFormation.
-
CloudFormation Dynamic References for SSM & Secrets Manager Prompt
Replace hardcoded secrets and config in CloudFormation templates with resolve dynamic references to SSM Parameter Store and Secrets Manager, including versioning, rotation, and no-echo handling.
-
CloudFormation Macros & Template Transform Authoring Prompt
Design and safely operate CloudFormation macros (Lambda-backed template transforms) to DRY up templates, inject standards, and expand shorthand — with idempotency, error handling, and change-set safety.
-
Pulumi Transformations & Aliases Refactor Prompt
Refactor Pulumi resource names, parents, and structure at scale using aliases and stack transformations so URNs change on paper but no live resource is destroyed or replaced.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
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.