Cloud Custodian Mailer
raw JSON → 0.6.49 verified Fri May 01 auth: no python
Cloud Custodian Mailer is a reference mailer implementation for sending email notifications from Cloud Custodian policies. Version 0.6.49 requires Python >=3.9,<4.0. It is released irregularly alongside Cloud Custodian releases.
pip install c7n-mailer Common errors
error ModuleNotFoundError: No module named 'c7n_mailer' ↓
cause c7n-mailer is not installed or installed into a different Python environment.
fix
Run 'pip install c7n-mailer' in the correct environment.
error botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the SendEmail operation: The security token included in the request is invalid. ↓
cause AWS credentials missing or expired, or the IAM role assumed does not have ses:SendEmail permission.
fix
Check AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) and IAM policy attached to the role used by c7n-mailer.
error KeyError: 'queue_url' ↓
cause Mailer config dictionary missing required 'queue_url' key.
fix
Ensure config includes 'queue_url': 'https://sqs.<region>.amazonaws.com/<account-id>/<queue-name>'
Warnings
breaking c7n-mailer 0.6.x uses 'c7n_mailer' imports, not 'c7n.mailer'. Older docs may reference the old dotted path. ↓
fix Use 'from c7n_mailer import Mailer' instead of 'from c7n.mailer import mailer'.
gotcha The 'queue_url' config must point to an SQS queue that is subscribed to the SNS topic used by Cloud Custodian policies. Misconfiguration leads to no emails sent. ↓
fix Ensure your SQS queue has a subscription to the SNS topic where Cloud Custodian publishes messages. Verify the queue ARN and policy allow SNS to send.
gotcha The 'from_address' must be verified in AWS SES (or sending domain verified) to send emails. Common reason for silent failures. ↓
fix Verify the email address or domain in AWS SES console. Use SES sandbox mode only for verified recipients.
deprecated Python 3.8 support dropped in c7n-mailer 0.6.42 (requires >=3.9). Upgrade Python environment if still on 3.8. ↓
fix Set requires-python = ">=3.9" in your environment or use an older c7n-mailer version if locked to 3.8.
Imports
- Mailer wrong
from c7n.mailer import Mailercorrectfrom c7n_mailer import Mailer - AwsMailer wrong
from c7n_mailer import AwsMailercorrectfrom c7n_mailer.aws import AwsMailer
Quickstart
from c7n_mailer import Mailer
config = {
'queue_url': 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue',
'region': 'us-east-1',
'role': 'arn:aws:iam::123456789012:role/my-mailer-role',
'from_address': 'security@example.com'
}
mailer = Mailer(config, session=None)
# For production, use a proper session or pass boto3 session