-
Notifications
You must be signed in to change notification settings - Fork 23
/
serverless.yml
216 lines (188 loc) · 7.03 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# NB -- PLEASE CONFIGURE THIS BY EDITING THE `config.yml` FILE
# Do edit the Serverless definition directly unless you know what you're doing...
#
####################################################################################################
service: backup-tasks
provider:
name: aws
region: ${file(./config.yml):AWS_REGION}
memorySize: 1024
# deploymentBucket should be pre-created via a tool like Terraform, and in the same region as where you are deploying the lambda function.
# deploymentBucket: ${file(./config.yml):deploymentBucket}
# Lambda now supports timeouts of up to 15 minutes :) -- https://aws.amazon.com/about-aws/whats-new/2018/10/aws-lambda-supports-functions-that-can-run-up-to-15-minutes/
timeout: 900
runtime: nodejs12.x
profile: ${file(./config.yml):AWS_PROFILE}
stage: prd
environment:
# NB: comma's after variable read from file are the default variables...
region: ${file(./config.yml):AWS_REGION, 'us-east-1'}
AWS_PROFILE: ${file(./config.yml):AWS_PROFILE, 'default'}
S3_BUCKET: ${file(./config.yml):S3_BUCKET}
EC2_WORKER_ROLE: ${file(./config.yml):EC2_WORKER_ROLE, 'AWSBackupTasksRoleForS3'}
EC2_KEYPAIR_NAME: ${file(./config.yml):EC2_KEYPAIR_NAME, ''}
EC2_WORKER_SIZE: ${file(./config.yml):EC2_WORKER_SIZE, 'm4.large'}
iamRoleStatements:
- Effect: "Allow"
# Allow AWS X-Ray & Cloudwatch Logs permissions for all functions...
Action:
- xray:PutTelemetryRecords
- xray:PutTraceSegments
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
plugins:
- serverless-offline
- serverless-offline-scheduler
- serverless-iam-roles-per-function
- serverless-local-schedule
functions:
## Copy important tags from EC2 instances to their EBS Volumes - AWS Should pull their finger out of their a** and do this out of the box by now!...
copyTags:
handler: functions/ec2/copy-tags.handler
events:
# No need for a special schedule here - Copying of tags to EBS volumes should run every 15 minutes...
- schedule: rate(15 minutes)
# Function needs access to EC2 Tags
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "ec2:CreateTags"
- "ec2:Describe*"
Resource:
- "*"
## Function to run daily and trigger EBS volume snapshots/cleanup...
snapshotVolumes:
handler: functions/ebs/ebs-snapshots.snapshotVolumes
events:
# Run backup each night, midnight time.
- schedule:
# ${file(./config.yml):BACKUP_SCHEDULE, 'cron(0 1 * * ? *)'}
rate: cron(0 1 * * ? *)
timezone: ${file(./config.yml):BACKUP_TIMEZONE, 'UTC'}
# Function needs access to EC2 Snapshot Management
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "ec2:CreateSnapshot"
- "ec2:DeleteSnapshot"
- "ec2:CreateTags"
- "ec2:ModifySnapshotAttribute"
- "ec2:ResetSnapshotAttribute"
- "ec2:Describe*"
Resource:
- "*"
purgeSnapshots:
handler: functions/ebs/ebs-snapshots.purgeSnapshots
events:
# Run backup each night, midnight time.
- schedule:
#${file(./config.yml):BACKUP_SCHEDULE, 'cron(0 1 * * ? *)'}
rate: cron(0 1 * * ? *)
timezone: ${file(./config.yml):BACKUP_TIMEZONE, 'UTC'}
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "ec2:CreateSnapshot"
- "ec2:DeleteSnapshot"
- "ec2:CreateTags"
- "ec2:ModifySnapshotAttribute"
- "ec2:ResetSnapshotAttribute"
- "ec2:Describe*"
Resource:
- "*"
## Daily function to export Route53 Records and save in S3...
backupRoute53:
# runtime: nodejs8.10
handler: functions/route53/cli53-backup-zones.handler
events:
# Run backup each night, midnight time.
- schedule:
# ${file(./config.yml):BACKUP_SCHEDULE, 'cron(0 1 * * ? *)'}
rate: cron(0 1 * * ? *)
timezone: ${file(./config.yml):BACKUP_TIMEZONE, 'UTC'}
# Function needs access to Route53 & the ability to upload into S3.
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "route53:Get*"
- "route53:List*"
- "s3:PutObject"
- "s3:PutObjectAcl"
- "s3:GetObject"
- "s3:GetObjectAcl"
Resource:
- "*"
## Daily function to dump RDS RDS Databases into S3 Bucket...
backupRDS:
handler: functions/rds/scan-rds.handler
events:
# Run backup each night, midnight time.
- schedule:
# ${file(./config.yml):BACKUP_SCHEDULE, 'cron(0 1 * * ? *)'}
rate: cron(0 1 * * ? *)
timezone: ${file(./config.yml):BACKUP_TIMEZONE, 'UTC'}
# Function needs access to Route53 & the ability to upload into S3.
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "rds:DescribeDBInstances"
- "rds:ListTagsForResource"
- "ec2:CreateTags"
- "ec2:DescribeImages"
- "ec2:RunInstances"
- "iam:PassRole"
Resource:
- "*"
## Daily function to dump any EFS Network share directories into the S3 Bucket...
backupEFS:
handler: functions/efs/scan-efs.handler
events:
# Run backup each night, midnight time.
- schedule:
# ${file(./config.yml):BACKUP_SCHEDULE, 'cron(0 1 * * ? *)'}
# Run backup/cron every 7 days - not every day...
rate: cron(0 1 */7 * ? *)
timezone: ${file(./config.yml):BACKUP_TIMEZONE, 'UTC'}
# Function needs access to Route53 & the ability to upload into S3.
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
# There's a bug with the below permissions, and some additional actions need to be added...
# Due to lack of time constraints this has been parked for now and needs to be re-addressed when there is spare time.
- "*"
# - "elasticfilesystem:Describe*"
# - "ec2:CreateTags"
# - "ec2:DescribeImages"
# - "ec2:RunInstances"
# - "iam:PassRole"
Resource:
- "*"
## Daily function to dump any ElastiCache Redis Databases into the S3 Bucket...
backupElastiCache:
handler: functions/elasticache/scan-elasticache.handler
events:
# Run backup each night, midnight time.
- schedule:
#${file(./config.yml):BACKUP_SCHEDULE, 'cron(0 1 * * ? *)'}
rate: cron(0 1 * * ? *)
timezone: ${file(./config.yml):BACKUP_TIMEZONE, 'UTC'}
# Function needs access to Route53 & the ability to upload into S3.
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "elasticache:*"
- "ec2:CreateTags"
- "ec2:DescribeImages"
- "ec2:RunInstances"
- "iam:PassRole"
Resource:
- "*"