-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
144 lines (136 loc) · 5.06 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
service: copy-or-take-snapshots
frameworkVersion: '2'
provider:
name: aws
runtime: python3.8
lambdaHashingVersion: 20201221
# you can overwrite defaults here
region: us-east-1
# you can add statements to the Lambda function's IAM Role here
resources:
Resources:
roleForProd:
Type: AWS::IAM::Role
Properties:
RoleName: RoleForProd
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: myPolicyName
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "rds:DescribeDBInstances"
- "rds:DescribeDBClusters"
- "rds:DescribeDBClusterSnapshots"
- "rds:DescribeDBSnapshots"
- "rds:AddTagsToResource"
- "rds:CreateDBClusterSnapshot"
- "rds:CreateDBSnapshot"
- "rds:CopyDBClusterSnapshot"
- "rds:CopyDBSnapshot"
- "rds:ModifyDBClusterSnapshotAttribute"
- "rds:ModifyDBSnapshotAttribute"
- "rds:DeleteDBClusterSnapshot"
- "rds:DeleteDBSnapshot"
- "kms:DescribeKey"
- "kms:CreateGrant"
Resource: [
"arn:aws:rds:${self:provider.stage}:*:db:*",
"arn:aws:rds:${self:provider.stage}:*:cluster:*",
"arn:aws:rds:${self:provider.stage}:*:cluster-snapshot:*",
"arn:aws:rds:${self:provider.stage}:*:snapshot:*",
"arn:aws:kms:${self:provider.stage}:*:key/*"
]
roleForDev:
Type: AWS::IAM::Role
Properties:
RoleName: RoleForDev
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: myPolicyName
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow # note that these rights are given in the default policy and are required if you want logs out of your lambda(s)
Action:
- "rds:DescribeDBInstances"
- "rds:DescribeDBClusters"
- "rds:DescribeDBClusterSnapshots"
- "rds:DescribeDBSnapshots"
- "rds:AddTagsToResource"
- "rds:CreateDBInstance"
- "rds:CopyDBClusterSnapshot"
- "rds:CopyDBSnapshot"
- "rds:ModifyDBCluster"
- "rds:ModifyDBInstance"
- "rds:ModifyDBClusterSnapshotAttribute"
- "rds:ModifyDBSnapshotAttribute"
- "rds:DeleteDBClusterSnapshot"
- "rds:DeleteDBSnapshot"
- "rds:RestoreDBClusterFromSnapshot"
- "rds:RestoreDBInstanceFromDBSnapshot"
- "rds:DeleteDBCluster"
- "rds:DeleteDBInstance"
- "kms:DescribeKey"
- "kms:CreateGrant"
Resource: [
"arn:aws:rds:${self:provider.stage}:*:db:*",
"arn:aws:rds:${self:provider.stage}:*:cluster:*",
"arn:aws:rds:${self:provider.stage}:*:cluster-snapshot:*",
"arn:aws:rds:${self:provider.stage}:*:snapshot:*",
"arn:aws:rds:${self:provider.stage}:*:subgrp:*",
"arn:aws:kms:${self:provider.stage}:*:key/*"
]
environment:
AWS_TARGET_KMS_KEY: ${self:custom.awsTargetKmsKey.${self:provider.stage}}
AWS_TARGET_ACCOUNT: ${self:custom.awsTargetAccount.${self:provider.stage}}
LOG_LEVEL: info
functions:
lambda_handler_prod:
stages:
- prod
role: roleForProd
handler: copy_or_take_snapshots.lambda_handler
timeout: 60
events:
- schedule: cron(0/5 4-7 ? * * *)
# generate lambda for Developmente account, (stage == dev)
lambda_handler_dev:
stages:
- dev
role: roleForDev
handler: restore_snapshots.lambda_handler
timeout: 60
events:
- schedule: cron(0/5 4-7 ? * * *)
custom:
pythonRequirements:
useDownloadCache: false
slim: true
# Replace these values with the correctly KMS key
awsTargetKmsKey:
dev: arn:aws:kms:us-east-1:111111111111:key/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
prod: arn:aws:kms:us-east-1:22222222222:key/ffffffff-gggg-hhhh-iiii-jjjjjjjjjjjj
# Replace these values with correctly AWS account numbers
awsTargetAccount:
dev: 222222222222
prod: 111111111111
plugins:
- serverless-python-requirements
- serverless-plugin-select