CloudFormation Best Practices

VerifiedSafe

CloudFormation template optimization, nested stacks, drift detection, and production-ready patterns.

Sby Skills Guide Bot
DevOpsIntermediate
7/23/2026
Claude CodeCursorWindsurfCopilotCodex
#aws-cloudformation#infrastructure-as-code#aws#iac-templates#nested-stacks

Recommended for

Automated summary

Guides the writing, review, and optimization of AWS CloudFormation templates (YAML/JSON), including nested stacks, cross-stack references, and drift handling.

Strengths

  • Concrete, actionable rules: YAML over JSON, environment parameterization, multi-environment Conditions, !Sub preferred over !Join
  • Covers production safeguards: DeletionPolicy/UpdateReplacePolicy on stateful resources and Outputs/Export for cross-stack references
  • Ships a specific troubleshooting recipe for stacks stuck in UPDATE_ROLLBACK_FAILED via continue-update-rollback
  • Bakes validation and linting (validate-template, cfn-lint, cfn-nag) into CI pipelines

Limitations

  • Does not cover CDK or Terraform, and explicitly tells you to skip it in those cases
  • Little guidance on migrating existing infrastructure or on detailed cost optimization despite the optimization framing
  • Examples are minimal (a single VPC template) relative to complex nested-stack architectures
When to use it

Use it when writing or reviewing raw CloudFormation templates, designing nested stack architectures, or debugging stack failures and drift.

When not to use it

Avoid it when the team uses CDK or Terraform, or when the task is application code rather than infrastructure.

Security analysis

Safe
Quality score86/100

The skill is purely instructional and contains no executable commands, scripts, credential handling, network calls, or destructive operations. It references AWS CLI validation and linting tools as best practices, but does not instruct the agent to run them or modify infrastructure automatically.

No concerns found

How this analysis is made

Examples

Review a production template
Review this CloudFormation YAML template for production readiness: check DeletionPolicy on our RDS and S3 resources, flag hardcoded ARNs, and tell me where I should use !Sub instead of !Join.
Split a monolithic stack
Our single CloudFormation template has 60 resources including VPC, ECS service, and RDS. Propose a nested stack or cross-stack export architecture and show the Outputs/Export wiring.
Fix a stuck rollback
My CloudFormation stack is stuck in UPDATE_ROLLBACK_FAILED after an RDS update. Walk me through continue-update-rollback with --resources-to-skip and how to fix the root cause.

name: cloudformation-best-practices description: "CloudFormation template optimization, nested stacks, drift detection, and production-ready patterns. Use when writing or reviewing CF templates." risk: unknown source: community date_added: "2026-02-27"

You are an expert in AWS CloudFormation specializing in template optimization, stack architecture, and production-grade infrastructure deployment.

Use this skill when

  • Writing or reviewing CloudFormation templates (YAML/JSON)
  • Optimizing existing templates for maintainability and cost
  • Designing nested or cross-stack architectures
  • Troubleshooting stack creation/update failures and drift

Do not use this skill when

  • The user prefers CDK or Terraform over raw CloudFormation
  • The task is application code, not infrastructure

Instructions

  1. Use YAML over JSON for readability.
  2. Parameterize environment-specific values; use Mappings for static lookups.
  3. Apply DeletionPolicy: Retain on stateful resources (RDS, S3, DynamoDB).
  4. Use Conditions to support multi-environment templates.
  5. Validate templates with aws cloudformation validate-template before deployment.
  6. Prefer !Sub over !Join for string interpolation.

Examples

Example 1: Parameterized VPC Template

AWSTemplateFormatVersion: "2010-09-09"
Description: Production VPC with public and private subnets

Parameters:
  Environment:
    Type: String
    AllowedValues: [dev, staging, prod]
  VpcCidr:
    Type: String
    Default: "10.0.0.0/16"

Conditions:
  IsProd: !Equals [!Ref Environment, prod]

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: !Ref VpcCidr
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: !Sub "${Environment}-vpc"

Outputs:
  VpcId:
    Value: !Ref VPC
    Export:
      Name: !Sub "${Environment}-VpcId"

Best Practices

  • ✅ Do: Use Outputs with Export for cross-stack references
  • ✅ Do: Add DeletionPolicy and UpdateReplacePolicy on stateful resources
  • ✅ Do: Use cfn-lint and cfn-nag in CI pipelines
  • ❌ Don't: Hardcode ARNs or account IDs — use !Sub with pseudo parameters
  • ❌ Don't: Put all resources in a single monolithic template

Troubleshooting

Problem: Stack stuck in UPDATE_ROLLBACK_FAILED Solution: Use continue-update-rollback with --resources-to-skip for the failing resource, then fix the root cause.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/cloudformation-best-practices-mrx3xymc' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/cloudformation-best-practices-mrx3xymc/download' --output '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md.part' && mv '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md.part' '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md' && test -s '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/cloudformation-best-practices' && cp -R '.skill-downloads/cloudformation-best-practices-mrx3xymc' '.claude/skills/cloudformation-best-practices'

Cursor
test -f '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md' && test -s '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/cloudformation-best-practices' && cp -R '.skill-downloads/cloudformation-best-practices-mrx3xymc' '.cursor/skills/cloudformation-best-practices'

Codex
test -f '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md' && test -s '.skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/cloudformation-best-practices' && cp -R '.skill-downloads/cloudformation-best-practices-mrx3xymc' '.agents/skills/cloudformation-best-practices'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/cloudformation-best-practices-mrx3xymc'

openskills read 'cloudformation-best-practices-mrx3xymc'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/cloudformation-best-practices-mrx3xymc/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills