Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPTCursor

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.

Target user
Cloud engineers building reusable CloudFormation tooling
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a cloud platform engineer authoring a CloudFormation macro — a Lambda that transforms a template fragment (or whole template) at deploy time — to eliminate boilerplate, enforce org standards (tags, encryption, naming), or expand a terse custom shorthand into full resources. Macros run inside the deploy pipeline, so a buggy one breaks every stack that uses it.

I will provide:
- What the macro should do (global vs. resource-level `Fn::Transform`), and example input/desired output
- The target resource types and the standards to inject
- Constraints (regions, accounts, whether change sets are mandatory)

Your job:

1. **Scope the transform** — decide global macro (in `Transform:` at template top, sees the whole template) vs. snippet macro (`Fn::Transform` on a fragment). Explain the processing order relative to `AWS::Include`, nested stacks, and other macros, and where that ordering bites.

2. **Author the Lambda** — give the handler that reads `event.fragment`, `event.templateParameterValues`, and `event.requestId`, mutates the fragment, and returns `{ requestId, status: "success", fragment }`. Handle the failure path: any exception or `status != success` fails the whole change set. Show defensive parsing so malformed input fails loudly, not silently.

3. **Idempotency & purity** — the transform must be a pure function of its input: no reliance on wall-clock, no external mutation, deterministic output so the same template always yields the same processed template. Flag anything non-deterministic (timestamps, random names) and how to make it stable.

4. **Safety with change sets** — because macros run before the change set is computed, always deploy macro-using stacks via change sets so you can review the *processed* template (`aws cloudformation describe-change-set` / `get-template --template-stage Processed`) before executing. Show those commands.

5. **Versioning & blast radius** — how to version the macro Lambda so a change does not silently alter every dependent stack, and how to test the transform locally against sample fragments before publishing.

Output as: (a) the macro-scope decision with processing-order notes, (b) the Lambda handler with success/failure contract, (c) determinism guarantees and what to remove, (d) the change-set review commands and a versioning/rollout plan. Assume many production stacks will depend on this macro.

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.