ScriptsApr 16, 2026·3 min read

Cloud Custodian — Cloud Security & Cost Governance Rules Engine

A YAML-based rules engine for managing cloud resources across AWS, Azure, and GCP. Cloud Custodian enforces security policies, optimizes costs, and ensures compliance through automated actions on non-compliant resources.

TL;DR
Cloud Custodian enforces security, cost, and compliance policies across AWS, Azure, and GCP using simple YAML rules.
§01

What it is

Cloud Custodian is a CNCF-hosted rules engine that lets teams define cloud governance policies in YAML. Each policy specifies a resource type (EC2 instances, S3 buckets, Azure VMs), filters to match non-compliant resources, and actions to remediate (tag, stop, terminate, encrypt, notify). It supports AWS, Azure, GCP, and Kubernetes.

Cloud Custodian is built for DevOps engineers, security teams, and FinOps practitioners who need automated enforcement of security posture, compliance mandates, and cost optimization rules across multi-cloud environments.

§02

How it saves time or tokens

Without Custodian, teams write ad-hoc scripts per cloud provider to audit resources. Custodian replaces those scripts with a declarative DSL -- one YAML file per policy. The engine handles API pagination, rate limiting, credential management, and retry logic. Policies run as Lambda functions or Cloud Functions for real-time event-driven enforcement, eliminating cron-based audit lag. For AI workflows, the YAML format is concise enough that generating or reviewing policies consumes minimal tokens.

§03

How to use

  1. Install the CLI: pip install c7n (add c7n-azure or c7n-gcp for non-AWS clouds).
  2. Write a policy YAML file defining resource type, filters, and actions.
  3. Run the policy: custodian run -s output policy.yml. Results are written to the output directory.
§04

Example

policies:
  - name: s3-require-encryption
    resource: s3
    filters:
      - type: bucket-encryption
        state: false
    actions:
      - type: notify
        subject: 'Unencrypted S3 bucket found'
        to:
          - security-team@example.com
        transport:
          type: sqs
          queue: custodian-notifications

This policy scans all S3 buckets, filters those without encryption enabled, and sends a notification via SQS.

§05

Related on TokRepo

§06

Common pitfalls

  • Running policies with destructive actions (terminate, delete) without first doing a dry run. Always test with --dryrun before applying actions that modify or remove resources.
  • Forgetting to scope policies by region. By default Custodian runs in your default region only. Use --region all or specify regions explicitly for global coverage.
  • Not setting up proper IAM roles for Lambda-mode policies. Custodian needs permissions to both read resources and perform the configured actions.

Frequently Asked Questions

What cloud providers does Cloud Custodian support?+

Cloud Custodian supports AWS natively with the core c7n package. Azure support is available via c7n-azure, GCP via c7n-gcp, and Kubernetes via c7n-kube. Each provider has its own set of resource types, filters, and actions.

Can Cloud Custodian run policies in real time?+

Yes. Custodian can deploy policies as AWS Lambda functions triggered by CloudTrail events, enabling real-time enforcement. When a non-compliant resource is created, the policy runs immediately rather than waiting for a scheduled scan.

How does Cloud Custodian handle cost optimization?+

Custodian includes filters for identifying underutilized resources (low CPU, zero connections), unattached volumes, old snapshots, and untagged resources. Actions can stop, resize, or terminate wasteful resources automatically.

Is Cloud Custodian suitable for large-scale environments?+

Yes. Custodian is used in production by organizations managing thousands of AWS accounts. It supports multi-account execution via c7n-org, which runs policies across an AWS Organization or a list of accounts in parallel.

What is the difference between Cloud Custodian and AWS Config Rules?+

AWS Config Rules are AWS-native and limited to AWS resources. Cloud Custodian is open-source, multi-cloud, and offers richer filter logic and action types. Custodian policies are portable YAML files rather than Lambda code tied to AWS Config.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets