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.
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.
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.
How to use
- Install the CLI:
pip install c7n(addc7n-azureorc7n-gcpfor non-AWS clouds). - Write a policy YAML file defining resource type, filters, and actions.
- Run the policy:
custodian run -s output policy.yml. Results are written to the output directory.
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.
Related on TokRepo
- DevOps AI tools -- infrastructure automation and cloud management tools
- Security AI tools -- security scanning and compliance utilities
Common pitfalls
- Running policies with destructive actions (terminate, delete) without first doing a dry run. Always test with
--dryrunbefore applying actions that modify or remove resources. - Forgetting to scope policies by region. By default Custodian runs in your default region only. Use
--region allor 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
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.
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.
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.
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.
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)
- Cloud Custodian GitHub— Cloud Custodian is a CNCF project with 400+ built-in filters
- Cloud Custodian Documentation— Supports AWS, Azure, GCP, and Kubernetes resource management
- Cloud Custodian Lambda Docs— Lambda-mode policies for real-time event-driven enforcement
Related on TokRepo
Discussion
Related Assets
doctest — The Fastest Feature-Rich C++ Testing Framework
doctest is a single-header C++ testing framework designed for minimal compile-time overhead and maximum speed.
Chai — BDD/TDD Assertion Library for Node.js
Chai is a flexible assertion library for Node.js and browsers that supports expect, should, and assert styles.
Supertest — HTTP Assertion Library for Node.js APIs
Supertest provides a high-level API for testing HTTP servers in Node.js with fluent assertion chaining.