Cloud-custodian: Policy variables

Created on 21 Apr 2018  路  3Comments  路  Source: cloud-custodian/cloud-custodian

I'm new to Cloud Custodian, doing an exploratory install, and I've run into a few issues. I think the answer to all three is variables but they aren't really discussed in the documentation.

1) My cloud custodian reports are going to PagerDuty (e-mail integration) so the alerting mechanism is going to be mostly the same for each policy. I would like to define the alerting parameters like to-address (in one place instead of per policy, or tagging all my AWS resources with addresses, or setting up an ldap server for a handful of addresses.

2) I see that the logging can be done either to cloudwatch, s3, or a local directory. Is there someplace I can specify a default logging configuration so that I don't have to do it for every invocation?

3) I have a number of resource types which I'm expecting a couple tags to be present and set to one of a list of known values. I believe I will need to write a policy for each resource type, but I think I can use a variable to define the tag logic once.

Example welcome - or links to any blogs that explain the variables feature better.

kinquestion

Most helpful comment

@thisisshi @kapilt Thank you both!

I was able to get a configuration working like this:

vars:
  notify-var: &notify-var
    - type: notify
      template: default
      to:
        - test-cloud-custodian@xxx
      transport:
        type: sqs
        queue: https://sqs.us-east-1.amazonaws.com/00000000/c7n-mailer

policies:
  - name: c7n-mailer-test
    resource: sqs
    filters:
     - "tag:DummyTag": absent
    actions:
      - <<: *notify-var
        subject: Testing the c7n mailer

All 3 comments

  1. you can use yaml anchors to reduce repeated statements, i.e.:
vars:
  notify-var: &notify-var
    - type: notify
      to: [email protected]
     # more stuff....

policies:
  - name: some-policy
    resource: ec2
    actions:
      <<: *notify-var

More info here: https://blog.daemonl.com/2016/02/yaml.html

  1. the log group has to be specified with the -l flag each time
  2. you should be able to do so with vars similar to the example in (1)

re 2. people typically have a front end script for the invocation or in their cron job, etc.

@thisisshi @kapilt Thank you both!

I was able to get a configuration working like this:

vars:
  notify-var: &notify-var
    - type: notify
      template: default
      to:
        - test-cloud-custodian@xxx
      transport:
        type: sqs
        queue: https://sqs.us-east-1.amazonaws.com/00000000/c7n-mailer

policies:
  - name: c7n-mailer-test
    resource: sqs
    filters:
     - "tag:DummyTag": absent
    actions:
      - <<: *notify-var
        subject: Testing the c7n mailer
Was this page helpful?
0 / 5 - 0 ratings

Related issues

danmarcab picture danmarcab  路  3Comments

twitherspoon picture twitherspoon  路  4Comments

jtroberts83 picture jtroberts83  路  4Comments

engineertree5 picture engineertree5  路  3Comments

JohnHillegass picture JohnHillegass  路  4Comments