-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
82 lines (75 loc) · 2.5 KB
/
serverless.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
# Welcome to Serverless!
#
service: scalingRDS
custom:
MasterEndpoint: "${env:MasterEndpoint}"
HostedZoneId: "${env:HostedZoneId}"
RecordName: "${env:RecordName}"
ReplicaEndpoint: "${env:ReplicaEndpoint}"
InstanceIdentifier: "${env:InstanceIdentifier}"
InstanceClassSmall: "${env:InstanceClassSmall}"
InstanceClassBig: "${env:InstanceClassBig}"
NotificationSNS: "${env:NotificationSNS}"
MsgError: "${env:MsgError}"
MsgRoutingToMaster: "${env:MsgRoutingToMaster}"
MsgRoutingToReplica: "${env:MsgRoutingToReplica}"
MsgScaleUp: "${env:MsgScaleUp}"
MsgScaleDown: "${env:MsgScaleDown}"
provider:
name: aws
runtime: nodejs6.10
stage: "${env:ENVIRONMENT}"
region: "${env:AWS_REGION}"
environment:
NotificationSNS: "${self:custom.NotificationSNS}"
MsgError: "${self:custom.MsgError}"
iamRoleStatements:
- Effect: "Allow"
Action:
- "route53:ChangeResourceRecordSets"
Resource: "arn:aws:route53:::hostedzone/${self:custom.HostedZoneId}"
- Effect: "Allow"
Action:
- "rds:ModifyDBInstance"
Resource: "arn:aws:rds:${env:AWS_REGION}:${env:AWS_ACCOUNT_ID}:db:${self:custom.InstanceIdentifier}"
- Effect: "Allow"
Action:
- "SNS:Publish"
Resource: "${self:custom.NotificationSNS}"
functions:
routingToMaster:
handler: route53.changeRecord
environment:
Msg: "${self:custom.MsgRoutingToMaster}"
HostedZoneId: "${self:custom.HostedZoneId}"
RecordName: "${self:custom.RecordName}"
RecordValue: "${self:custom.MasterEndpoint}"
events:
- schedule: cron(00 08 ? * TUE,THU *)
- schedule: cron(00 15 ? * TUE,THU *)
scaleUp:
handler: rds.scale
environment:
Msg: "${self:custom.MsgScaleUp}"
InstanceIdentifier: "${self:custom.InstanceIdentifier}"
InstanceClass: "${self:custom.InstanceClassBig}"
events:
- schedule: cron(05 08 ? * TUE,THU *)
scaleDown:
handler: rds.scale
environment:
Msg: "${self:custom.MsgScaleDown}"
InstanceIdentifier: "${self:custom.InstanceIdentifier}"
InstanceClass: "${self:custom.InstanceClassSmall}"
events:
- schedule: cron(05 15 ? * TUE,THU *)
routingToReplica:
handler: route53.changeRecord
environment:
Msg: "${self:custom.MsgRoutingToReplica}"
HostedZoneId: "${self:custom.HostedZoneId}"
RecordName: "${self:custom.RecordName}"
RecordValue: "${self:custom.ReplicaEndpoint}"
events:
- schedule: cron(15 08 ? * TUE,THU *)
- schedule: cron(15 15 ? * TUE,THU *)