Registry / devops / c7n
library0.9.51pypypi✓ verified 24d ago

Cloud Custodian (c7n) is an open-source, cloud-native rules engine for managing public cloud accounts and resources. It enables users to define policies in simple YAML files to ensure well-managed, secure, and cost-optimized cloud infrastructure. It supports major cloud providers like AWS, Azure, and GCP, and can execute policies in real-time (via serverless functions) or periodically (via scheduled jobs). The current version is 0.9.50, and it maintains an active release cadence with frequent updates and feature additions.

pip install c7n
INSTALL
IMPORT
SIG · C7N
C
c7n
devopspythonv0.9.51
Install
11.7s avg
Import
1666ms
Disk
80MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.51 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.723s · 79.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 21.1s · import 1.610s · 80MB
80MB installed
● package 80MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Policy
from c7n.policy import Policy
Cloud Custodian is primarily a CLI tool. Direct Python imports are mostly for advanced use cases like building custom extensions, testing, or programmatic policy loading, not typical end-user policy execution.

This quickstart demonstrates how to define a simple policy in a YAML file (`policy.yml`) to identify unencrypted S3 buckets in AWS and then execute it using the `custodian` CLI tool. The `--dryrun` flag allows you to preview actions without making actual changes. Ensure your AWS credentials are configured (e.g., via `~/.aws/credentials` or environment variables) for `custodian` to interact with your cloud environment.

# policy.yml policies: - name: find-unencrypted-s3-buckets resource: aws.s3 filters: - type: unencrypted actions: # Remove or comment out 'actions' for a pure dry-run without notification setup - type: notify violation_messages: - "S3 bucket {resource_id} in {account_id} is not encrypted!" to: - "{{ resource_owner_email | default(owner@example.com) }}" transport: type: sqs # Requires c7n-mailer and an SQS queue named 'cloud-custodian-notifications' queue: cloud-custodian-notifications # To run the policy (ensure AWS credentials are configured): custodian run --dryrun -s . policy.yml
custodian --version
Debug
Known issues
gotchaForgetting to install cloud-specific packages (e.g., `c7n_azure`, `c7n_gcp`) will lead to errors when trying to run policies for those providers, as the necessary resource modules will be missing.
fix
Always install the base `c7n` package along with the specific package(s) for your target cloud(s), e.g., `pip install c7n c7n_azure`.
affects: All versions
gotchaAlways use the `--dryrun` flag when developing or testing new policies, especially those with `actions`. This prevents unintended modifications or deletions of cloud resources by showing what actions *would* be taken.
fix
Execute `custodian run --dryrun -s . policy.yml` to review policy impact before running without `--dryrun`.
affects: All versions
gotchaCloud Custodian policies are written in YAML. Incorrect YAML syntax (e.g., indentation errors, missing `policies:` root key) is a common cause of `PolicyValidationError` or `YAMLError` during execution.
fix
Use a YAML linter or editor with YAML validation. Ensure the policy file starts with `policies:` followed by a list of policy definitions.
affects: All versions
breakingCloud Custodian currently requires Python >=3.10.2 and <4.0.0. Using older Python versions will result in installation failures or runtime errors due to dropped support.
fix
Upgrade your Python environment to a supported version (e.g., Python 3.10.x or 3.11.x).
affects: <0.9.0 (earlier versions supported older Python)
gotchaProper cloud provider credentials must be configured in the execution environment (e.g., AWS CLI configuration, environment variables like `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` for AWS). Without them, policies cannot interact with cloud APIs.
fix
Refer to your cloud provider's SDK/CLI documentation for credential configuration. For AWS, ensure `~/.aws/credentials` and `~/.aws/config` are set up, or relevant environment variables are exported.
affects: All versions
gotchaFor managing policies across multiple cloud accounts, subscriptions, or projects in parallel, the `c7n-org` tool is necessary. Running `custodian` directly will only target the configured account/region.
fix
Install `c7n-org` (`pip install c7n_org`) and use its configuration and commands for multi-target execution.
affects: All versions
gotchaWhen deploying real-time policies using 'mode' (e.g., `cloudtrail`, `periodic`), Cloud Custodian automatically provisions serverless functions (like AWS Lambda). Incorrect or insufficient IAM permissions for the Custodian execution role can lead to deployment failures or policy execution errors within the serverless environment.
fix
Ensure the IAM role used by Cloud Custodian has the necessary permissions to provision cloud resources (e.g., Lambda functions, CloudWatch Events) and to perform the actions defined in your policies. Consult the Cloud Custodian documentation's 'IAM Setup' section for detailed requirements.
affects: All versions
Errors
Common errors & fixes
NoCredentialsError('Unable to locate credentials')
Cloud Custodian cannot find the necessary cloud provider credentials (e.g., AWS credentials) in the environment where it is being executed to perform operations.
fix
Ensure that AWS credentials are configured correctly via environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN), a shared credentials file (~/.aws/credentials), or by associating an appropriate IAM role with the execution environment.
ModuleNotFoundError: No module named 'c7n_azure'
A required Cloud Custodian extension module for a specific cloud provider (e.g., Azure, GCP, AWS-CC) or a core dependency for a c7n tool (like c7n-mailer or c7n-left) has not been installed. The error might also appear for 'c7n_gcp', 'c7n_awscc', 'c7n.mu', or even 'c7n' itself if a related tool is installed without the main library.
fix
Install the missing module using pip: `pip install c7n-azure` (or `pip install c7n-gcp`, `pip install c7n-awscc`, `pip install cloud-custodian` as appropriate). Ensure all necessary components are installed, potentially in the correct order, especially when dealing with specific versions.
invalid policy file: <filename>.yaml error: policy:%s cant mix credential and access-key filters w/ delete action
The Cloud Custodian policy contains a logical inconsistency or an unsupported combination of filters and actions, specifically attempting to mix 'credential' and 'access-key' filters with a 'delete' action for IAM access keys.
fix
Review the policy logic for IAM access key management. If the goal is to disable keys, use the 'update' action instead of 'delete' when combining 'credential' and 'access-key' filters. Consult the Cloud Custodian documentation for the specific resource type and supported actions/filters.
yaml: line X: found character that cannot start any token
The Cloud Custodian policy YAML file has a syntax error, such as incorrect indentation, missing colons, invalid characters, or an improperly formed key-value pair.
fix
Correct the YAML syntax in the policy file, paying close attention to indentation (ensure consistent use of spaces, not tabs) and proper key-value pair formatting. Use a YAML linter (e.g., 'yamllint') to help identify the exact location and nature of the syntax error.
Upgrade
Version history
0.9.51latest on PyPI · released May 28, 2026
Audit
Dependencies
pythonrequiredRuntime environment
c7n_azureoptionalRequired for Azure policies
c7n_gcpoptionalRequired for GCP policies
c7n_ocioptionalRequired for OCI policies
Agent activity
50 hits · last 30 days
node
42
OpenAI (training)
1
Resources
c7n — pip install c7n · libregistry