Help Further understand the onhour filters.

138 views
Skip to first unread message

deji...@gmail.com

unread,
May 15, 2017, 1:10:55 PM5/15/17
to cloud-custodian

Hello I love the idea of using cloud custodian in my current AWS environment.  The primary use case I have for cloud custodian is to stop instances at night and bring them up in mornings based on tags.

My attempt to implement cloud custodian went like this.

I could install cloud custodian easily which excited me.

I could run a policy which would stop instances with whatever desired tag I chose.  Which excited me.

When I attempted to create a policy that would start instances at the desired time and then stop them at desired time.

Policy I used

<<< 

policies:

  - name: after-hours-start

    resource: ec2

    filters:

      - type: onhour

        tag: "StartAfterHours"

        default_tz: est

        onhour: 14

    actions:

      - stop

  - name: after-hours-stop

    resource: ec2

    filters:

      - type: offhour

        tag: "StopAfterHours"

        default_tz: est

        offhour: 15

    actions:

      - start

>>> 

 

I ran above yaml at about 2:30 and was able to shut down an instance. However I can’t really create the scenario by changing the time in the  onhour and offhour spots.

A lot of times I get this behavior when running my policies.

2017-05-14 19:17:14,204: custodian.policy:INFO Running policy start-morning-instances resource: ec2 region:us-east-1

2017-05-14 19:17:14,500: custodian.filters:INFO InstanceOnHour 1 of 9 instances

2017-05-14 19:17:14,500: custodian.policy:INFO policy: start-morning-instances resource:ec2 has count:0 time:0.30

2017-05-14 19:17:14,501: custodian.policy:INFO Running policy stop-night-instances resource: ec2 region:us-east-1 

2017-05-14 19:17:14,501: custodian.filters:INFO InstanceOffHour 8 of 9 instances

2017-05-14 19:17:14,502: custodian.policy:INFO policy: stop-night-instances resource:ec2 has count:0 time:0.00

Which is bad because I want it to count the instance and shut it down or spin up.

So, my question is can anybody help me further understand when I should be executing my on and off policies. Also, understand when the policies are executed and how long that it executes.  Open to all suggestions regarding starting and stopping instances at a desired time with cloud custodian.

Kapil Thangavelu

unread,
Jun 21, 2017, 9:20:34 PM6/21/17
to cloud-custodian
offhour/onhour only matches at the hour in instance tag or default policy value  in question is the  common gotcha here.
Reply all
Reply to author
Forward
0 new messages