New to Claude Skills? Learn how to install them →

sickn33 on GitHub

CloudFormation Best Practices

Free

Optimize your AWS CloudFormation templates effectively.

Get this skill

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 source

1. Install with the skills CLI

npx skills add sickn33/agentic-awesome-skills/cloudformation-best-practices --agent claude-code

2. 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 sickn33

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.

Frequently asked questions about CloudFormation Best Practices

Similar skills