Notifications with Cloud Custodian

2,171 views
Skip to first unread message

André Smink

unread,
May 24, 2016, 3:32:20 AM5/24/16
to cloud-custodian
Hi

Is it possible to use cloud custodian to send a notification containing a list of non compliant services using an SNS topic and tag those services for cleanup?

Currently I have a policy that creates a lambda function that stops all EC2 instances with no Owner tag but I want to change it so that it tags the instances with
a message that says it will be terminated in 7 days and send a notification using SNS with a list of all those instances.

Kapil Thangavelu

unread,
Jun 5, 2016, 6:39:17 AM6/5/16
to cloud-custodian

There is a notify action that relays a data message to an sqs queue that can be combined with mark-for-op (delayed action) and filters to achieve that effect. But the sqs worker/mailer delivery side of that is currently not part of the opensource code at the moment due to integration with org specific ldap/address lookup, and resource-owner tag to address mapping. At the moment that means actual delivery is diy. The message format is base64 encoded gzip'd json, with the policy, and resources in the payload. I've filed a github issue to track this at https://github.com/capitalone/cloud-custodian/issues/163 but its not on the short term 3 week roadmap due to competing priorities.

cheers,

Kapil

devops...@gmail.com

unread,
Dec 1, 2016, 9:35:42 AM12/1/16
to cloud-custodian


Hi Andre

Can you help me in writing policy that creates lambda function ? Or if you could share the policy you stated above, that would be great.

devops...@gmail.com

unread,
Dec 1, 2016, 9:37:39 AM12/1/16
to cloud-custodian
Hi Kapil,

I just started exploring this tool and I am trying to create lambda functions with custodian policies. Can you help me with this ??

Mandeep Bal

unread,
Dec 1, 2016, 11:53:47 AM12/1/16
to cloud-custodian
Hi,

This is an example of a lambda policy from our github Readme.md.

- name: ec2-require-non-public-and-encrypted-volumes
  resource: ec2
  description: |
    Provision a lambda and cloud watch event target
    that looks at all new instances and terminates those with
    unencrypted volumes.
  mode:
    type: cloudtrail
    events:
        - RunInstances
  filters:
    - type: ebs
      key: Encrypted
      value: false
  actions:
    - terminate

John Du

unread,
Feb 22, 2017, 4:30:20 PM2/22/17
to cloud-custodian
I am new to custodian. using ebs.actions.notify sends SNS email of finding unattached volumes. But the email content is un-readable and base64 decode not change anything. How can I get the email contents readable? Any help is appreciated. John

here is the policy (only topic arn and email address not in real)
---
policies:
- name: ebs-find-unattached
  resource: ebs
  comments: |
    find volumes that are not used.
  filters:
    - Attachments: []
    - "tag:maid_status": present
  actions:
    - type: notify
      to:
      subject: "Un-used Volumes found"
      template: default
      transport:
        type: sns
        topic: arn:aws:sns:us-east-1:xxxxxxxxxxx:AWSDevOps
...

Linus Yong

unread,
Feb 23, 2017, 2:02:29 AM2/23/17
to cloud-custodian
Hi John,

It is first compressed using zlib, then base64 encoded.  To get the plan text:
  • Copy the text into a file (e.g. result)
  • Then decode the text using:
$ cat result | base64 -D > result.zlib
$ printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - result.zlib | gzip -dc
  • The printf is just to pad a proper header for gzip.  Otherwise gzip will not be able to uncompress it.

Linus Yong

unread,
Feb 23, 2017, 2:06:26 AM2/23/17
to cloud-custodian
You might also want to look at the code here: http://www.capitalone.io/cloud-custodian/docs/_modules/c7n/actions.html#Notify.send_sns

Message=base64.b64encode(zlib.compress(utils.dumps(message)))

John Du

unread,
Feb 23, 2017, 9:43:53 AM2/23/17
to cloud-custodian
Hi Linus,

Thank you very much for replying with the details.

Is it possible that put the email contents in  plain text? Such as I can do something in the policy file?

Kind Regards,

John

Linus Yong

unread,
Feb 26, 2017, 9:26:36 PM2/26/17
to cloud-custodian
Hi John,

You can't just send the message as plain text using the policies YAML file.  You can change the code of http://www.capitalone.io/cloud-custodian/docs/_modules/c7n/actions.html#Notify.send_sns if you want.
Reply all
Reply to author
Forward
0 new messages