-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
487 lines (451 loc) · 14.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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
plugins:
- serverless-python-requirements
- serverless-domain-manager
custom: ${file(./parameters.yml)}
service:
name: devops-ecs-resources # NOTE: update this with your service name
frameworkVersion: 1.0.0.0
provider:
name: aws
runtime: python2.7
role: arn:aws:iam::${self:custom.nonprod_accountid}:role/Containerization_Lambda_Deployment
region: ${self:custom.region}
stackTags:
version: 1.0.0.0
resourcePolicy:
- Effect: Allow
Principal:
AWS:
- ${self:custom.admin_sso_role_arn}
- ${self:custom.poweruser_sso_role_arn}
- ${self:custom.dev3_sso_role_arn}
Action: execute-api:Invoke
Resource:
- execute-api:/*/POST/stacks
- execute-api:/*/DELETE/stacks
- execute-api:/*/POST/stacks/deploytoNonProd
- execute-api:/*/POST/stacks/deploytoProdBlue
- execute-api:/*/POST/stacks/swapProdBlueAndGreen
- Effect: Allow
Principal:
AWS:
- ${self:custom.dev1_sso_role_arn}
- ${self:custom.dev2_sso_role_arn}
Action: execute-api:Invoke
Resource:
- execute-api:/*/POST/stacks
- execute-api:/*/POST/stacks/deploytoNonProd
- Effect: Deny
Principal:
AWS:
- ${self:custom.dev1_sso_role_arn}
- ${self:custom.dev2_sso_role_arn}
Action: execute-api:Invoke
Resource:
- execute-api:/*/DELETE/stacks
- execute-api:/*/POST/stacks/deploytoProdBlue
- execute-api:/*/POST/stacks/swapProdBlueAndGreen
functions:
createstackapi:
name: createstackapi
handler: createstackapi.lambda_handler
timeout: 900
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
PROD_ACC: ${self:custom.prod_accountid}
CF_TEMPLATE: ${self:custom.cftemplate}
DEVQA_VPC: ${self:custom.devqa_vpc}
STAGE_VPC: ${self:custom.stage_vpc}
TRAINING_VPC: ${self:custom.training_vpc}
DA_VPC: ${self:custom.da_vpc}
PROD_VPC: ${self:custom.prod_vpc}
DEVQA_SUBNET: ${self:custom.devqa_subnet}
STAGE_SUBNET: ${self:custom.stage_subnet}
TRAINING_SUBNET: ${self:custom.training_subnet}
DA_SUBNET: ${self:custom.da_subnet}
PROD_SUBNET: ${self:custom.prod_subnet}
DEVQA_ALBSUBNET: ${self:custom.devqa_elbsubnet}
STAGE_ALBSUBNET: ${self:custom.stage_elbsubnet}
TRAINING_ALBSUBNET: ${self:custom.training_elbsubnet}
DA_ALBSUBNET: ${self:custom.da_elbsubnet}
PROD_ALBSUBNET: ${self:custom.prod_elbsubnet}
DEVQA_SG: ${self:custom.devqa_sg}
STAGE_SG: ${self:custom.stage_sg}
TRAINING_SG: ${self:custom.training_sg}
DA_SG: ${self:custom.da_sg}
PROD_SG: ${self:custom.prod_sg}
DEVQA_ALBSG: ${self:custom.devqa_elbsg}
STAGE_ALBSG: ${self:custom.stage_elbsg}
TRAINING_ALBSG: ${self:custom.training_elbsg}
DA_ALBSG: ${self:custom.da_elbsg}
PROD_ALBSG: ${self:custom.prod_elbsg}
REPO_URI: ${self:custom.repouri}
HOSTEDZONE_NAME: ${self:custom.hostedzonename}
PROD_HOSTEDZONE_NAME: ${self:custom.prodhostedzonename}
ADMIN_ROLEARN: ${self:custom.admin_rolearn}
EXECUTION_ROLENAME: ${self:custom.execution_rolename}
STSROLEARN: ${self:custom.stsrolearn}
NONPROD_CERTARN: ${self:custom.nonprod_certarn}
PROD_CERTARN: ${self:custom.prod_certarn}
ECSAUTOSCALING_ARN: ${self:custom.ecsautoscaling_arn}
PROD_ECSAUTOSCALING_ARN: ${self:custom.prod_ecsautoscaling_arn}
LIFECYCLEPOLICYTEXT: ${self:custom.ecrlifecyclepolicytext}
events:
- http:
path: /stacks
method: post
authorizer: aws_iam
cors: true
deletestackapi:
name: deletestackapi
handler: deletestackapi.lambda_handler
timeout: 30
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
PROD_ACC: ${self:custom.prod_accountid}
REGION: ${self:custom.region}
STSROLEARN: ${self:custom.stsrolearn}
events:
- http:
path: /stacks
method: delete
authorizer: aws_iam
cors: true
ecsdeploytononprodapi:
name: ecsdeploytoNonProdApi
handler: ecsdeploytoNonProdApi.lambda_handler
timeout: 300
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
DEVQA_VPC: ${self:custom.devqa_vpc}
STAGE_VPC: ${self:custom.stage_vpc}
TRAINING_VPC: ${self:custom.training_vpc}
DA_VPC: ${self:custom.da_vpc}
DEVQA_SUBNET: ${self:custom.devqa_subnet}
STAGE_SUBNET: ${self:custom.stage_subnet}
TRAINING_SUBNET: ${self:custom.training_subnet}
DA_SUBNET: ${self:custom.da_subnet}
DEVQA_SG: ${self:custom.devqa_sg}
STAGE_SG: ${self:custom.stage_sg}
TRAINING_SG: ${self:custom.training_sg}
DA_SG: ${self:custom.da_sg}
STSROLEARN: ${self:custom.stsrolearn}
events:
- http:
path: /stacks/deploytoNonProd
method: post
authorizer: aws_iam
cors: true
ecsdeploytoprodblueapi:
name: ecsdeploytoProdBlueApi
handler: ecsdeploytoProdBlueApi.lambda_handler
timeout: 300
environment:
PROD_VPC: ${self:custom.prod_vpc}
PROD_SUBNET: ${self:custom.prod_subnet}
PROD_SG: ${self:custom.prod_sg}
STSROLEARN: ${self:custom.stsrolearn}
STSROLE_PROD: ${self:custom.stsrole_prod}
PROD_ACC: ${self:custom.prod_accountid}
events:
- http:
path: /stacks/deploytoProdBlue
method: post
authorizer: aws_iam
cors: true
ecsdeploytotraindaapi:
name: ecsdeploytoTrainDAApi
handler: ecsdeploytoTrainDAApi.lambda_handler
timeout: 300
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
DEVQA_VPC: ${self:custom.devqa_vpc}
STAGE_VPC: ${self:custom.stage_vpc}
TRAINING_VPC: ${self:custom.training_vpc}
DA_VPC: ${self:custom.da_vpc}
DEVQA_SUBNET: ${self:custom.devqa_subnet}
STAGE_SUBNET: ${self:custom.stage_subnet}
TRAINING_SUBNET: ${self:custom.training_subnet}
DA_SUBNET: ${self:custom.da_subnet}
DEVQA_SG: ${self:custom.devqa_sg}
STAGE_SG: ${self:custom.stage_sg}
TRAINING_SG: ${self:custom.training_sg}
DA_SG: ${self:custom.da_sg}
STSROLEARN: ${self:custom.stsrolearn}
events:
- http:
path: /stacks/deploytoTrainDA
method: post
authorizer: aws_iam
cors: true
swapprodapi:
name: swapprodapi
handler: swapprodapi.lambda_handler
timeout: 10
environment:
STSROLEARN: ${self:custom.stsrolearn}
STSROLE_PROD: ${self:custom.stsrole_prod}
PROD_ACC: ${self:custom.prod_accountid}
events:
- http:
path: /stacks/swapProdBlueAndGreen
method: post
authorizer: aws_iam
cors: true
ecssnsnotifications:
name: ecssnsnotifications
handler: ecssnsnotifications.lambda_handler
timeout: 10
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
events:
- cloudwatchEvent:
event:
source:
- "aws.ecs"
detail-type:
- "ECS Task State Change"
addSubscriptions:
name: addSubscriptions
handler: addSubscriptions.lambda_handler
timeout: 5
environment:
STSROLE_PROD: ${self:custom.stsrole_prod}
NONPROD_ACC: ${self:custom.nonprod_accountid}
PROD_ACC: ${self:custom.prod_accountid}
events:
- http:
path: /stacks/addSubscription
method: post
authorizer: aws_iam
cors: true
applicationinfo:
name: applicationinfoapi
handler: applicationinfoapi.lambda_handler
timeout: 30
environment:
STSROLEARN: ${self:custom.stsrolearn}
events:
- http:
path: /stacks/applicationInfo
method: post
authorizer: aws_iam
cors: true
nonprodaction:
name: nonprodstatusapi
handler: nonprodstatusapi.lambda_handler
timeout: 30
environment:
STSROLEARN: ${self:custom.stsrolearn}
NONPROD_ACC: ${self:custom.nonprod_accountid}
events:
- http:
path: /stacks/nonprodStatus
method: post
authorizer: aws_iam
cors: true
prodblueaction:
name: prodbluestatusapi
handler: prodbluestatusapi.lambda_handler
timeout: 30
environment:
STSROLEARN: ${self:custom.stsrolearn}
STSROLE_PROD: ${self:custom.stsrole_prod}
events:
- http:
path: /stacks/prodblueStatus
method: post
authorizer: aws_iam
cors: true
devopsstackinfo:
name: devopsstackinfoapi
handler: devopsstackinfoapi.lambda_handler
timeout: 30
events:
- http:
path: /stacks/devopsstackInfo
method: post
authorizer: aws_iam
cors: true
cfstackset_notification:
name: cfstackset_notification
handler: cfstackset_notification.lambda_handler
timeout: 300
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
events:
- cloudwatchEvent:
event:
source:
- "aws.cloudformation"
ecr_notifications:
name: ecr_notifications
handler: ecr_notifications.lambda_handler
timeout: 300
environment:
NONPROD_ACC: ${self:custom.nonprod_accountid}
events:
- cloudwatchEvent:
event:
source:
- "aws.ecr"
# you can add CloudFormation resource templates here
resources:
Resources:
Repository:
Type: AWS::ECR::Repository
Properties:
RepositoryName: devopsrepo
RepositoryPolicyText:
Version: "2008-10-17"
Statement:
-
Sid: CrossAccountPull
Effect: Allow
Principal:
AWS:
- "arn:aws:iam::${self:custom.prod_accountid}:root"
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
Cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: DevOpsCluster
AgeroECSCFTemplateS3:
Type: AWS::S3::Bucket
Properties:
BucketName: agero-coreautomation-ecs-cf-template
VersioningConfiguration:
Status: Enabled
AgeroECSCFTemplateBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: agero-coreautomation-ecs-cf-template
PolicyDocument:
Version: '2012-10-17'
Statement:
- Principal:
AWS:
- Fn::Join:
- ''
-
- "arn:aws:iam::"
- ${self:custom.prod_accountid}
- ":root"
Action:
- "s3:GetObject"
- "s3:PutObject"
- "s3:PutObjectAcl"
Effect: "Allow"
Sid: "AddCrossAccountPermission"
Resource:
Fn::Join: ['', [ Fn::GetAtt: [AgeroECSCFTemplateS3, Arn], "/*"] ]
# DynamoECSInventoryNonProd:
# Type: AWS::DynamoDB::Table
# Properties:
# TableName: ECS_Inventory_NonProduction
# AttributeDefinitions:
# - AttributeName: "ApplicationName"
# AttributeType: "S"
# - AttributeName: "Environment"
# AttributeType: "S"
# KeySchema:
# - AttributeName: "ApplicationName"
# KeyType: "HASH"
# - AttributeName: "Environment"
# KeyType: "RANGE"
# ProvisionedThroughput:
# ReadCapacityUnits: "5"
# WriteCapacityUnits: "5"
# DynamoECSInventoryProd:
# Type: AWS::DynamoDB::Table
# Properties:
# TableName: ECS_Inventory_Production
# AttributeDefinitions:
# - AttributeName: "ApplicationName"
# AttributeType: "S"
# - AttributeName: "Environment"
# AttributeType: "S"
# KeySchema:
# - AttributeName: "ApplicationName"
# KeyType: "HASH"
# - AttributeName: "Environment"
# KeyType: "RANGE"
# ProvisionedThroughput:
# ReadCapacityUnits: "5"
# WriteCapacityUnits: "5"
# DynamoECSInventoryTrainingDA:
# Type: AWS::DynamoDB::Table
# Properties:
# TableName: ECS_Inventory_Training_DA
# AttributeDefinitions:
# - AttributeName: "ApplicationName"
# AttributeType: "S"
# - AttributeName: "Environment"
# AttributeType: "S"
# KeySchema:
# - AttributeName: "ApplicationName"
# KeyType: "HASH"
# - AttributeName: "Environment"
# KeyType: "RANGE"
# ProvisionedThroughput:
# ReadCapacityUnits: "5"
# WriteCapacityUnits: "5"
# DynamoDevOpsLogs:
# Type: AWS::DynamoDB::Table
# Properties:
# TableName: DevOpsLogsTable
# AttributeDefinitions:
# - AttributeName: "ResourceName"
# AttributeType: "S"
# - AttributeName: "Time"
# AttributeType: "S"
# KeySchema:
# - AttributeName: "ResourceName"
# KeyType: "HASH"
# - AttributeName: "Time"
# KeyType: "RANGE"
# ProvisionedThroughput:
# ReadCapacityUnits: "5"
# WriteCapacityUnits: "5"
# Repository:
# Type: AWS::ECR::Repository
# Properties:
# RepositoryName: ${self:custom.apiname}
#
# Cluster:
# Type: AWS::ECS::Cluster
# Properties:
# ClusterName: ${self:custom.apiname}
#
# TaskDefinition:
# Type: AWS::ECS::TaskDefinition
# Properties:
# Cpu: 1024
# ExecutionRoleArn: arn:aws:iam::${self:custom.accountid}:role/ecsTaskExecutionRole
# Memory: 2048
# NetworkMode: awsvpc
# RequiresCompatibilities:
# - FARGATE
# TaskRoleArn: arn:aws:iam::${self:custom.accountid}:role/ecsTaskExecutionRole
# ContainerDefinitions:
# - Image: 377558703253.dkr.ecr.us-east-1.amazonaws.com/${self:custom.apiname}
# Name: ${self:custom.apiname}
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"