-
Notifications
You must be signed in to change notification settings - Fork 6
/
serverless.example.yml
445 lines (440 loc) · 14 KB
/
serverless.example.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
service: cidr-house-rules
plugins:
- serverless-aws-documentation
- serverless-plugin-aws-alerts
custom:
alerts:
stages:
- production
topics:
alarm:
topic: ${self:service}-${opt:stage}-alerts-alarm
notifications:
- protocol: email
endpoint: name@domain.com # Change this to your email address
definitions:
functionErrors:
threshold: 5
alarms:
- functionErrors
- functionThrottles
documentation:
info:
version: "1"
title: "cidr-house-rules"
description: "A lightweight API to expose important AWS resource information across multiple accounts in near-realtime
"
termsOfService: ""
contact:
name: "Silver Mullet"
url: "https://github.com/silvermullet/cidr-house-rules/Readme.md"
email: ""
provider:
name: aws
runtime: python3.6
region: us-west-2
apiKeys:
- my_api_key
timeout: 300
stackTags:
Product: cidr-house-rules
Owner:
Team: dataplatform
environment:
DYNAMODB_TABLE_CIDRS: ${self:service}-${opt:stage, self:provider.stage}-cidrs
DYNAMODB_TABLE_ACCOUNTS: ${self:service}-${opt:stage, self:provider.stage}-accounts
DYNAMODB_TABLE_NAT_GATEWAYS: ${self:service}-${opt:stage, self:provider.stage}-nat-gateways
DYNAMODB_TABLE_EIP: ${self:service}-${opt:stage, self:provider.stage}-eip
DYNAMODB_TABLE_ELB: ${self:service}-${opt:stage, self:provider.stage}-elb
DYNAMODB_TABLE_AVAILABLE_IPS: ${self:service}-${opt:stage, self:provider.stage}-available-ips
DYNAMODB_TABLE_ENDPOINT_SERVICES: ${self:service}-${opt:stage, self:provider.stage}-endpoint-services
ENV: ${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action: lambda:InvokeFunction
Resource: "*"
- Effect: Allow
Action: sts:AssumeRole
Resource:
- "arn:aws:iam::<add_remote_account_number_here>:role/role_cidr_house"
- "arn:aws:iam::<add_another_remote_account_number_here>:role/role_cidr_house"
- "arn:aws:iam::<and_add_another_remote_account_number_here>:role/role_cidr_house"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_CIDRS}"
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_ACCOUNTS}"
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_NAT_GATEWAYS}"
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_EIP}"
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_ELB}"
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_AVAILABLE_IPS}"
- "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE_ENDPOINT_SERVICES}"
- Effect: Allow
Action:
- ec2:Describe*
Resource:
- "*"
functions:
runner-available_ips:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-available_ips
events:
- schedule:
rate: cron(0,30 * * * ? *)
runner-import_cidrs:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-import_cidrs
events:
- schedule:
rate: cron(5,35 * * * ? *)
runner-import_nat_gateways:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-import_nat_gateways
events:
- schedule:
rate: cron(8,38 * * * ? *)
runner-import_eips:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-import_eips
events:
- schedule:
rate: cron(10,40 * * * ? *)
runner-import_elbs_classic:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-import_elbs_classic
events:
- schedule:
rate: cron(12,42 * * * ? *)
runner-import_elbsv2:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-import_elbsv2
events:
- schedule:
rate: cron(14,44 * * * ? *)
runner-import_endpoint_services:
handler: runner.runner
environment:
run: cidr-house-rules-${opt:stage, self:provider.stage}-import_endpoint_services
events:
- schedule:
rate: cron(16,47 * * * ? *)
import_cidrs:
handler: import_cidrs.import_cidrs
memorySize: 128
environment:
ttl_expire_time: 172800
available_ips:
handler: available_ips.available_ips
memorySize: 128
environment:
ttl_expire_time: 172800
import_nat_gateways:
handler: import_nat_gateways.import_nat_gateways
memorySize: 128
environment:
ttl_expire_time: 172800
import_eips:
handler: import_eips.import_eips
memorySize: 128
environment:
ttl_expire_time: 172800
import_elbs_classic:
handler: import_elbs_classic.import_elbs
memorySize: 128
environment:
ttl_expire_time: 172800
import_elbsv2:
handler: import_elbsv2.import_elbs
memorySize: 128
environment:
ttl_expire_time: 172800
events:
- schedule: rate(1 hour)
import_endpoint_services:
handler: import_endpoint_services.import_endpoint_services
memorySize: 128
environment:
ttl_expire_time: 172800
check_conflict:
handler: api_handlers.check_conflict
events:
- http:
path: check_conflict
method: get
private: true
documentation:
summary: "Check input CIDR for conflicts with existing CIDRs"
description: "Check input CIDR for conflicts with existing CIDRs"
tags:
- "vpc"
- "networking"
- "ec2:Describe"
requestBody:
description: "Empty body"
requestHeaders:
-
name: "X-Api-Key"
description: "Requires an active API key for accessing this function"
queryParams:
-
name: "cidr"
description: "provide the cidr block to check for conflicts against, ie 10.16.0.0/16"
methodResponses:
-
statusCode: "200"
responseBody:
description: "*** Warning, Range overlaps with another in organization *** OR OK, no CIDR conflicts"
add_account:
handler: api_handlers.add_account
events:
- http:
path: add_account
method: get
private: true
documentation:
summary: "Add a new AWS Account to cidr-house-rules service"
description: "This will add a new account number and alias name to DynamoDB accounts table"
tags:
- "accounts"
requestBody:
description: "Empty body"
requestHeaders:
-
name: "X-Api-Key"
description: "Requires an active API key for accessing this function"
queryParams:
-
name: "account"
description: "provide the AWS account number"
-
name: "team"
description: "provide the AWS account alias name"
methodResponses:
-
statusCode: "200"
responseBody:
description: "OK"
-
statusCode: "422"
responseBody:
description: "Invalid input"
get_nat_gateways_for_all:
handler: api_handlers.get_nat_gateways_for_all
events:
- http:
path: get_nat_gateways_for_all
method: get
private: true
documentation:
summary: "Return NAT Gateways for all teams"
requestBody:
description: "Empty body"
requestHeaders:
-
name: "X-Api-Key"
description: "Requires an active API key for accessing this function"
queryParams:
-
name: "results_per_page"
description: "provide the AWS account number, optional, used if page queyer is specified"
-
name: "page"
description: "provide the AWS account number, optional, default will return all results in one page"
get_number_of_nat_gateway_pages:
handler: api_handlers.get_number_of_nat_gateway_pages
events:
- http:
path: get_number_of_nat_gateway_pages
method: get
private: true
documentation:
summary: "Get the number of pages of NAT gateways with given number of results"
requestBody:
description: "Empty body"
requestHeaders:
-
name: "X-Api-Key"
description: "Requires an active API key for accessing this function"
queryParams:
-
name: "results_per_page"
description: "provide the AWS account number"
get_nat_gateways_for_team:
handler: api_handlers.get_nat_gateways_for_team
events:
- http:
path: get_nat_gateways_for_team
method: get
private: true
get_eips_for_team:
handler: api_handlers.get_eips_for_team
events:
- http:
path: get_eips_for_team
method: get
private: true
get_elbs_for_all:
handler: api_handlers.get_elbs_for_all
events:
- http:
path: get_elbs_for_all
method: get
private: true
get_service_endpoints_for_all:
handler: api_handlers.get_service_endpoints_for_all
events:
- http:
path: get_service_endpoints_for_all
method: get
private: true
get_service_endpoint_for_nlb:
handler: api_handlers.get_service_endpoint_for_nlb
events:
- http:
path: get_service_endpoint_for_nlb
method: get
private: true
resources:
Resources:
CIDRDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
Enabled: true
AttributeName: 'ttl'
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_CIDRS}'
AccountsDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_ACCOUNTS}'
NatGatewaysDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
Enabled: true
AttributeName: 'ttl'
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_NAT_GATEWAYS}'
EIPDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
Enabled: true
AttributeName: 'ttl'
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_EIP}'
ELBDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
Enabled: true
AttributeName: 'ttl'
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_ELB}'
AvailableIPsDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
Enabled: true
AttributeName: 'ttl'
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_AVAILABLE_IPS}'
EndpointServicesDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
Enabled: true
AttributeName: 'ttl'
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 5
TableName: '${self:provider.environment.DYNAMODB_TABLE_ENDPOINT_SERVICES}'