Cloud Custodian - Parallel Execution

0.6.49 · active · verified Thu Apr 09

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

Install

Quickstart

c7n-org operates via the command line, requiring an `accounts.yml` file that defines the target cloud accounts and regions, and Custodian policy files (e.g., `policy.yml`). This example demonstrates setting up these files and shows the command to run `c7n-org` to execute policies across multiple accounts and regions. For AWS, the `accounts.yml` can be dynamically generated using `c7n-org aws-accounts -f accounts.yml` if AWS Organizations is configured.

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')

view raw JSON →