Cloud Custodian - Parallel Execution
c7n-org is a command-line tool designed to execute Cloud Custodian policies across multiple cloud accounts (AWS, Azure, GCP, OCI) in parallel. It centralizes policy definition and enforcement for large cloud environments, simplifying governance and compliance at scale. The current version is 0.6.49, and it is regularly updated in conjunction with the main Cloud Custodian project.
Warnings
- breaking Python 3.9.2 is the minimum required version, and support is limited to Python 3.x (less than 4.0.0). Older Python versions are not supported.
- gotcha Executing policies across multiple accounts requires properly configured cross-account IAM roles (e.g., `OrganizationAccountAccessRole` for AWS) in each target account that `c7n-org` will assume. Without correct permissions, policies will fail silently or with access denied errors.
- gotcha The `c7n-org report` command currently only supports generating reports from locally stored output directories. It cannot directly process output stored in cloud object storage (e.g., S3).
- gotcha Logging from `c7n-org` can sometimes be too concise, hiding specific cloud provider error messages and making troubleshooting complex issues, especially permission-related ones, difficult.
- gotcha There have been reports of `c7n-org` encountering errors when targeting AWS accounts in non-default regions, potentially related to regional STS endpoints.
Install
-
pip install c7n-org
Quickstart
import os
# Create a dummy accounts.yml for demonstration
accounts_yaml_content = '''
accounts:
- account_id: '123456789012'
name: dev-account
regions:
- us-east-1
- us-west-2
role: arn:aws:iam::123456789012:role/CloudCustodian
- account_id: '987654321098'
name: prod-account
regions:
- us-east-1
role: arn:aws:iam::987654321098:role/CloudCustodian
'''
# Create a simple Custodian policy to find untagged S3 buckets
policy_yaml_content = '''
policies:
- name: untagged-s3-buckets
resource: aws.s3
filters:
- "tag:Project": absent
actions:
- type: notify
subject: Untagged S3 Bucket Found
to:
- email@example.com # Replace with a valid email for actual use
transport:
type: sqs
queue: https://sqs.us-east-1.amazonaws.com/123456789012/my-notification-queue
'''
# Write content to files
with open('accounts.yml', 'w') as f:
f.write(accounts_yaml_content)
with open('policy.yml', 'w') as f:
f.write(policy_yaml_content)
# Simulate running c7n-org via subprocess for demonstration
# In a real scenario, you would run this command in your shell
print("Simulating c7n-org execution...")
print("Command: c7n-org run -c accounts.yml -s output -p policy.yml")
print("\n--- Output Directory Structure ---")
print("output/")
print("├── dev-account/")
print("│ ├── us-east-1/")
print("│ │ └── untagged-s3-buckets/")
print("│ └── us-west-2/")
print("│ └── untagged-s3-buckets/")
print("└── prod-account/")
print(" └── us-east-1/")
print(" └── untagged-s3-buckets/")
print("----------------------------------")
# Cleanup dummy files
os.remove('accounts.yml')
os.remove('policy.yml')