forked from 1Strategy/cloud-custodian-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcost-control.yml
107 lines (100 loc) · 2.9 KB
/
cost-control.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# these policies should be run in the region containing your resources
policies:
#==================
# EC2
#==================
# turn instances off during non-business hours
- name: ec2-stop-instances-offhours
resource: ec2
mode:
type: periodic
role: arn:aws:iam::842337631775:role/custodian-cost-control
schedule: "rate(15 minutes)"
filters:
- "tag:Custodian": present
- type: offhour
tag: offhours
default_tz: pt
offhour: 20
actions:
- stop
- name: ec2-start-instances-onhours
resource: ec2
mode:
type: periodic
role: arn:aws:iam::842337631775:role/custodian-cost-control
schedule: "rate(15 minutes)"
filters:
- "tag:Custodian": present
- type: onhour
tag: offhours
default_tz: pt
onhour: 8
actions:
- start
# scale instance types
# note: generally, we recommend scaling instances out/in, using autoscaling groups, vs.
# scaling instances up/down (making a given instance larger or smaller). However, if
# you have folks who tend to over-provision instances, this can be helpful.
- name: ec2-change-underutilized-instance-type
resource: ec2
mode:
type: periodic
role: arn:aws:iam::842337631775:role/custodian-cost-control
schedule: "rate(1 day)"
# default timeout of 60 seconds isn't long enough to resize
timeout: 180
filters:
- "tag:Custodian": present
- type: value
key: "InstanceType"
op: in
value:
- "m4.10xlarge"
- "m4.4xlarge"
- type: metrics
name: CPUUtilization
value: 30
op: less-than
days: 3
period: 86400
actions:
- type: resize
type-map:
m4.10xlarge: m4.4xlarge
m4.4xlarge: m4.2xlarge
# terminate old instances; useful for sandbox/dev accounts
- name: ec2-terminate-old-instances
resource: ec2
mode:
type: periodic
role: arn:aws:iam::842337631775:role/custodian-cost-control
schedule: "rate(1 day)"
comment: |
# Terminate all instances that are tagged Custodian, and older than 30 days
filters:
- "tag:Custodian": present
- type: instance-age
days: 30
actions:
- terminate
- type: notify
template: default
subject: 'Old EC2 instance terminated'
to:
- arn:aws:sns:us-west-2:842337631775:cloud-custodian-mailer
transport:
type: sqs
queue: https://sqs.us-west-2.amazonaws.com/842337631775/cloud-custodian-mailer
# delete unattached EBS volumes; useful for sandbox/dev accounts
- name: ebs-delete-unattached-volumes
resource: ebs
mode:
type: periodic
role: arn:aws:iam::842337631775:role/custodian-cost-control
schedule: "rate(1 day)"
filters:
- "tag:Custodian": present
- Attachments: []
actions:
- delete