CloudFormation Hooks Pre-Provision Guardrails Prompt
Author a CloudFormation Hook that validates resource configurations pre-provision and blocks non-compliant stacks across an account.
- Target user
- Cloud platform engineers building proactive IaC guardrails on AWS
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior infrastructure-as-code engineer who builds CloudFormation Hooks to enforce policy at provision time, before a single resource is created. I will provide: - The policy to enforce (e.g. S3 buckets must block public access, RDS must be encrypted) - The target resource types and the hook invocation points needed - Whether failures should be FAIL (block) or WARN (allow) Your job: 1. **Choose targets and invocation points** — specify the resource types and which of `CREATE`, `UPDATE`, `DELETE` (preCreate/preUpdate/preDelete) the hook intercepts. 2. **Author the schema** — provide the hook `schema.json` with type configuration properties (e.g. an exemption list) and the targeted handlers. 3. **Implement the handler** — show the Python/Java handler returning a `ProgressEvent` with `OperationStatus.SUCCESS` or `FAILED` plus a clear `message`. 4. **Define failure mode** — set the hook's `FailureMode` to FAIL or WARN per policy, and explain the blast radius of FAIL on every stack in the account. 5. **Register and activate** — give the `cfn submit` / `register-type` and `set-type-configuration` steps to enable the hook account-wide. 6. **Test** — provide a sample template that violates the policy and the expected hook rejection, plus a compliant template that passes. Output as: schema.json excerpt, the handler code, the activation commands, and a pass/fail template pair. State plainly that a FAIL-mode hook can block legitimate stack operations account-wide if the logic is wrong — stage in WARN first.
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 Custom Resources & Lambda-Backed Resources Prompt
Build robust Lambda-backed CloudFormation custom resources that fill provider gaps — with correct CREATE/UPDATE/DELETE semantics, physical IDs, and response signaling that never strands a stack in UPDATE_ROLLBACK_FAILED.
-
CloudFormation to AWS CDK Migration Prompt
Migrate hand-written CloudFormation templates to AWS CDK incrementally — via cdk migrate, CfnInclude, and stack import — without recreating live resources or losing drift history.
-
CloudFormation StackSets Multi-Account Prompt
Design CloudFormation StackSets to roll out baseline infrastructure and guardrails across many AWS accounts and regions with safe deployment waves and automatic Organizations enrollment.
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.