
CloudFormation Best Practices
FreeOptimize your AWS CloudFormation templates effectively.
Free · Opens the source repo
What CloudFormation Best Practices does
The CloudFormation Best Practices skill is designed for developers and DevOps engineers who work with AWS CloudFormation. This skill provides expert guidance on writing and reviewing CloudFormation templates, focusing on optimization techniques that enhance maintainability and reduce costs. It covers essential practices for structuring templates, including the use of nested stacks and cross-stack architectures, which are vital for managing complex infrastructure deployments.
When using this skill, you will find detailed instructions on how to create efficient CloudFormation templates in both YAML and JSON formats. It emphasizes the importance of parameterizing environment-specific values and using Mappings for static lookups, which can significantly improve the flexibility of your templates. Additionally, it advises on best practices like applying DeletionPolicy: Retain for stateful resources to prevent accidental data loss during updates.
The skill also addresses common challenges faced during stack creation and updates, providing troubleshooting tips for scenarios such as UPDATE_ROLLBACK_FAILED. By following the outlined best practices and examples, users can ensure that their CloudFormation templates are production-ready and adhere to AWS standards.
This skill is particularly useful for teams looking to implement Infrastructure as Code (IaC) with CloudFormation, as it helps streamline the development process and minimizes the risk of errors in deployment.
When to use it
Use this skill when creating or reviewing CloudFormation templates to ensure best practices are followed and to troubleshoot issues effectively.
When not to use it
This skill is not suitable if you prefer using CDK or Terraform, or if your task involves application code rather than infrastructure.
What you can build with it
Optimizing a CloudFormation Template
When tasked with improving an existing CloudFormation template, use this skill to apply best practices for maintainability and cost.
Troubleshooting Stack Failures
If you encounter a stack stuck in `UPDATE_ROLLBACK_FAILED`, refer to the troubleshooting section for effective resolution steps.
Designing Nested Stacks
When designing a complex infrastructure setup, use this skill to implement nested stacks and ensure proper architecture.
How to install CloudFormation Best Practices
View source1. Install with the skills CLI
npx skills add sickn33/agentic-awesome-skills/cloudformation-best-practices --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by sickn33You 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
- Use YAML over JSON for readability.
- Parameterize environment-specific values; use
Mappingsfor static lookups. - Apply
DeletionPolicy: Retainon stateful resources (RDS, S3, DynamoDB). - Use
Conditionsto support multi-environment templates. - Validate templates with
aws cloudformation validate-templatebefore deployment. - Prefer
!Subover!Joinfor 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
OutputswithExportfor cross-stack references - ✅ Do: Add
DeletionPolicyandUpdateReplacePolicyon stateful resources - ✅ Do: Use
cfn-lintandcfn-nagin CI pipelines - ❌ Don't: Hardcode ARNs or account IDs — use
!Subwith 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.
Frequently asked questions about CloudFormation Best Practices
Similar skills
Turborepo
Optimized build system for JavaScript/TypeScript monorepos.
Azure Pipelines Validation
Streamline your Azure DevOps pipeline changes locally.
Azure Developer CLI
Streamline your Azure project workflows with best practices.
Azure Container Registry CLI
Manage Azure Container Registry resources with ease.
Aspire
Build and orchestrate polyglot distributed applications seamlessly.
Vercel CLI
Manage and deploy Vercel projects from the command line.
