-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_sam_template.yaml
519 lines (496 loc) · 17.7 KB
/
test_sam_template.yaml
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# This is the ECR version of the SAM template:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
starfleet
This is a Sample SAM Template for starfleet -- please replace this with your own and add your own values in.
See the Starfleet documentation here for more details: https://gemini-oss.github.io/starfleet/installation/Overview/
# Replace these with your own:
Parameters:
EnvironmentName:
Type: String
Default: TEST
AllowedValues:
- TEST
- PROD
Description: Informs the Lambda functions which configuration to use, either TEST or PROD
# Environment specific configuration can go in here:
Mappings:
EnvMap:
TEST:
# Add more values that can be referenced easily here:
BaseRoleName: starfleet-worker-basic-test-role
PROD:
# Add more values that can be referenced easily here:
BaseRoleName: starfleet-worker-basic-prod-role
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 300
Environment:
Variables:
GIT_PYTHON_REFRESH: quiet # Required for IAMbic in the IAM Role Worker
Resources:
# The Starbase Components
StarbaseFanoutDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: starbase-fanout-dlq
RedriveAllowPolicy:
redrivePermission: allowAll
StarbaseFanoutQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: starbase-fanout-queue
VisibilityTimeout: 300 # This needs to be the same as the Lambda function timeout.
RedrivePolicy:
deadLetterTargetArn: !GetAtt StarbaseFanoutDLQ.Arn
maxReceiveCount: 4
StarbaseFanoutQueuePolicy: # SQS policy to allow S3 bucket notifications
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !GetAtt StarbaseFanoutQueue.QueueUrl
PolicyDocument:
Statement:
- Effect: Allow
Action: SQS:SendMessage
Resource:
- !GetAtt StarbaseFanoutQueue.Arn
Principal:
Service: s3.amazonaws.com
Condition:
ArnLike:
"aws:SourceArn": !Sub
- 'arn:aws:s3:::starfleet-templates-${AccountId}'
- AccountId: !Ref "AWS::AccountId"
StringEquals:
"aws:SourceAccount": !Ref "AWS::AccountId"
StarfleetTemplateBucket:
DependsOn:
- StarbaseFanoutQueuePolicy
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub
- 'starfleet-templates-${AccountId}'
- AccountId: !Ref "AWS::AccountId"
PublicAccessBlockConfiguration:
BlockPublicAcls: True
BlockPublicPolicy: True
IgnorePublicAcls: True
RestrictPublicBuckets: True
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
NotificationConfiguration:
QueueConfigurations:
- Event: "s3:ObjectCreated:*"
Queue: !GetAtt StarbaseFanoutQueue.Arn
# The S3 bucket that holds the account index:
AccountIndexBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub
- 'starfleet-account-index-${AccountId}'
- AccountId: !Ref "AWS::AccountId"
PublicAccessBlockConfiguration:
BlockPublicAcls: True
BlockPublicPolicy: True
IgnorePublicAcls: True
RestrictPublicBuckets: True
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
# Secrets Manager for Starfleet secrets -- this is optional and disabled by default -- recommend you click ops this actually
#StarfleetSecrets:
# Type: AWS::SecretsManager::Secret
# Properties:
# Description: Secret storage for Starfleet secrets
# KmsKeyId: alias/aws/secretsmanager
# Name: StarfleetSecrets
# Tags:
# - Add here
# The Starbase EventBridge listener:
StarbaseEventBridgeFunction:
Type: AWS::Serverless::Function
Metadata:
DockerTag: starfleet
DockerContext: ./
Dockerfile: Dockerfile
Properties:
PackageType: Image
ImageConfig:
Command:
- starfleet.starbase.entrypoints.eventbridge_timed_lambda_handler
Architectures:
- arm64
Events:
# Make one for each timed event: -- Don't forget to set these to Enabled when you are ready to use them!
EventBridgeFiveMin:
Type: Schedule
Properties:
Name: StarfleetFiveMin
Description: Invokes Starfleet 5-minute worker ship tasks
Enabled: False # Disabled by default for cost unless you need this for some workers
Schedule: rate(5 minutes)
Input: '{"name": "FIVE_MIN"}'
EventBridgeFifteenMin:
Type: Schedule
Properties:
Name: StarfleetFifteenMin
Description: Invokes Starfleet 15-minute worker ship tasks
Enabled: False # Disabled by default for cost unless you need this for some workers
Schedule: rate(15 minutes)
Input: '{"name": "FIFTEEN_MIN"}'
EventBridgeThirtyMin:
Type: Schedule
Properties:
Name: StarfleetThirtyMin
Description: Invokes Starfleet 30-minute worker ship tasks
Enabled: False # Disabled by default for cost unless you need this for some workers
Schedule: rate(30 minutes)
Input: '{"name": "THIRTY_MIN"}'
EventBridgeHourly:
Type: Schedule
Properties:
Name: StarfleetHourly
Description: Invokes Starfleet hourly worker ship tasks
Enabled: True
Schedule: rate(1 hour)
Input: '{"name": "HOURLY"}'
EventBridgeSixHourly:
Type: Schedule
Properties:
Name: StarfleetSixHourly
Description: Invokes Starfleet six-hourly worker ship tasks
Enabled: True
Schedule: rate(6 hours)
Input: '{"name": "SIX_HOURLY"}'
EventBridgeTwelveHourly:
Type: Schedule
Properties:
Name: StarfleetTwelveHourly
Description: Invokes Starfleet twelve-hourly worker ship tasks
Enabled: True
Schedule: rate(12 hours)
Input: '{"name": "TWELVE_HOURLY"}'
EventBridgeDaily:
Type: Schedule
Properties:
Name: StarfleetDaily
Description: Invokes Starfleet daily worker ship tasks
Enabled: True
Schedule: rate(1 day)
Input: '{"name": "DAILY"}'
Policies:
# Grant permissions to read from the Template S3 bucket and also the account index bucket:
- S3ReadPolicy:
BucketName: !Ref StarfleetTemplateBucket
- S3ReadPolicy:
BucketName: !Ref AccountIndexBucket
# Write out to the fan out queue:
- SQSSendMessagePolicy:
QueueName: !GetAtt StarbaseFanoutQueue.QueueName
# #####
# Define the worker ships here:
# ####
# Account Index Generator Worker Ship Resources:
AccountIndexGeneratorDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: starfleet-account-index-generator-dlq
RedriveAllowPolicy:
redrivePermission: allowAll
AccountIndexGeneratorQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: starfleet-account-index-generator
VisibilityTimeout: 300 # This needs to be the same as the Lambda function timeout.
RedrivePolicy:
deadLetterTargetArn: !GetAtt AccountIndexGeneratorDLQ.Arn
maxReceiveCount: 4
AccountIndexGenerator:
Type: AWS::Serverless::Function
Metadata:
DockerTag: starfleet
DockerContext: ./
Dockerfile: Dockerfile
Properties:
PackageType: Image
ImageConfig:
Command:
- starfleet.worker_ships.plugins.account_index_generator.ship.lambda_handler
Architectures:
- arm64
MemorySize: 256
Events:
SQSEvent:
Type: SQS
Properties:
Queue: !GetAtt AccountIndexGeneratorQueue.Arn
BatchSize: 2
Environment:
Variables:
STARFLEET_COMMIT: True
Policies:
# Grant permissions to read and write to the inventory S3 bucket:
- S3ReadPolicy:
BucketName: !Ref AccountIndexBucket
- S3WritePolicy:
BucketName: !Ref AccountIndexBucket
# Uncomment for the AWS Config worker to have that set up and deployed:
# AWSConfigWorkerDLQ:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: starfleet-aws-config-worker-dlq
# RedriveAllowPolicy:
# redrivePermission: allowAll
#
# AWSConfigWorkerQueue:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: starfleet-aws-config-worker
# VisibilityTimeout: 300 # This needs to be the same as the Lambda function timeout.
# RedrivePolicy:
# deadLetterTargetArn: !GetAtt AWSConfigWorkerDLQ.Arn
# maxReceiveCount: 4
#
# AWSConfigWorker:
# Type: AWS::Serverless::Function
# Metadata:
# DockerTag: starfleet
# DockerContext: ./
# Dockerfile: Dockerfile
# Properties:
# PackageType: Image
# ImageConfig:
# Command:
# - starfleet.worker_ships.plugins.aws_config.ship.lambda_handler
# Architectures:
# - arm64
# MemorySize: 128
# Events:
# SQSEvent:
# Type: SQS
# Properties:
# Queue: !GetAtt AWSConfigWorkerQueue.Arn
# BatchSize: 2
# Environment:
# Variables:
# STARFLEET_COMMIT: False
# Policies:
# # Grant permissions to read from the inventory S3 bucket:
# - S3ReadPolicy:
# BucketName: !Ref AccountIndexBucket
# Uncomment for the GitHub Repo Sync Worker:
# GitHubSyncWorkerDLQ:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: starfleet-github-sync-worker-dlq
# RedriveAllowPolicy:
# redrivePermission: allowAll
#
# GitHubSyncWorkerQueue:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: starfleet-github-sync-worker
# VisibilityTimeout: 300 # This needs to be the same as the Lambda function timeout.
# RedrivePolicy:
# deadLetterTargetArn: !GetAtt GitHubSyncWorkerDLQ.Arn
# maxReceiveCount: 4
#
# GitHubSyncWorker:
# Type: AWS::Serverless::Function
# Metadata:
# DockerTag: starfleet
# DockerContext: ./
# Dockerfile: Dockerfile
# Properties:
# PackageType: Image
# ImageConfig:
# Command:
# - starfleet.worker_ships.plugins.github_sync.ship.lambda_handler
# Architectures:
# - arm64
# MemorySize: 128
# Events:
# SQSEvent:
# Type: SQS
# Properties:
# Queue: !GetAtt GitHubSyncWorkerQueue.Arn
# BatchSize: 2
# Environment:
# Variables:
# STARFLEET_COMMIT: False
# Policies:
# # Grant permissions to read and write to the templates bucket, so you can do CI/CD!
# - S3CrudPolicy:
# BucketName: !Ref StarfleetTemplateBucket
# # Add any additional S3 policies here!
# Uncomment for the IAM Role Worker:
# IamRoleWorkerDLQ:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: starfleet-iam-role-worker-dlq
# RedriveAllowPolicy:
# redrivePermission: allowAll
#
# IamRoleWorkerQueue:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: starfleet-iam-role-worker
# VisibilityTimeout: 300 # This needs to be the same as the Lambda function timeout.
# RedrivePolicy:
# deadLetterTargetArn: !GetAtt IamRoleWorkerDLQ.Arn
# maxReceiveCount: 4
#
# IamRoleWorker:
# Type: AWS::Serverless::Function
# Metadata:
# DockerTag: starfleet
# DockerContext: ./
# Dockerfile: Dockerfile
# Properties:
# PackageType: Image
# ImageConfig:
# Command:
# - starfleet.worker_ships.plugins.iam.role_ship.lambda_handler
# Architectures:
# - arm64
# MemorySize: 128
# Events:
# SQSEvent:
# Type: SQS
# Properties:
# Queue: !GetAtt IamRoleWorkerQueue.Arn
# BatchSize: 4
# Environment:
# Variables:
# STARFLEET_COMMIT: False
# GIT_PYTHON_REFRESH: quiet # Iambic
# Policies:
# # Grant permissions to read from the Account Inventory S3 bucket:
# - S3ReadPolicy:
# BucketName: !Ref AccountIndexBucket
# Finally, the Starbase Fanout Function:
StarbaseFanoutFunction:
Type: AWS::Serverless::Function
DependsOn:
- AccountIndexGeneratorQueue
Metadata:
DockerTag: starfleet
DockerContext: ./
Dockerfile: Dockerfile
Properties:
PackageType: Image
ImageConfig:
Command:
- starfleet.starbase.entrypoints.fanout_payload_lambda_handler
Architectures:
- arm64
Events:
# Make one for each timed event:
SQSEvent:
Type: SQS
Properties:
Queue: !GetAtt StarbaseFanoutQueue.Arn
BatchSize: 1 # Important! We only want 1 to ensure we don't hit timeouts.
Policies:
# Grant permissions to read from the Template S3 bucket:
- S3ReadPolicy:
BucketName: !Ref StarfleetTemplateBucket
- SQSSendMessagePolicy:
QueueName: starfleet-*
# Common worker ship components here:
AssumeRoleManagedPolicy:
Type: AWS::IAM::ManagedPolicy
DependsOn:
- AccountIndexGenerator
Properties:
Description: Grants Starfleet workers assume role permissions to common Starfleet worker IAM roles
ManagedPolicyName: StarfleetWorkerAssumeRoles
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: 'sts:AssumeRole'
Resource:
- !Sub
- 'arn:aws:iam::*:role/${RoleName}'
- RoleName: !FindInMap
- EnvMap
- !Ref 'EnvironmentName'
- BaseRoleName
# Uncomment for secrets manager permissions as well for Slack alerts and GitHub Repo Sync worker
# - Effect: Allow
# Action: secretsmanager:GetSecretValue
# Resource: arn:aws:secretsmanager:REGION:ACCOUNTNUMBER:secret:STARFLEET-SECRET-ID-HERE
Roles:
- !Ref AccountIndexGeneratorRole # AccountIndexGeneratorRole is created automatically by SAM and can be referenced
# - !Ref AWSConfigWorkerRole # Uncomment for the AWS Config worker
# - !Ref GitHubSyncWorkerRole # Uncomment for the GitHub Repo Sync Worker
# - !Ref IamRoleWorkerRole # Uncomment for the IAM Role Worker
# - !Ref YourWorkerRoleHere # Add your worker roles here to get the policy attached
Outputs:
StarbaseFanoutQueue:
Description: The Queue URL for the Starbase fan out queue
Value: !GetAtt StarbaseFanoutQueue.QueueUrl
StarbaseFanoutDLQ:
Description: The Queue URL for the Starbase fan out DLQ
Value: !GetAtt StarbaseFanoutDLQ.QueueUrl
StarfleetTemplateBucket:
Description: The Starfleet S3 bucket that holds all the worker ship templates
Value: !Ref StarfleetTemplateBucket
StarbaseEventBridgeFunction:
Description: The primary entrypoint for the Starbase timed EventBridge invocations
Value: !GetAtt StarbaseEventBridgeFunction.Arn
StarbaseFanoutFunction:
Description: The Starbase function that fans out the tasks to the worker ships
Value: !GetAtt StarbaseFanoutFunction.Arn
AssumeRoleManagedPolicy:
Description: The Assume Role managed policy that can be attached to worker roles that need it
Value: !Ref AssumeRoleManagedPolicy
AccountIndexBucket:
Description: The Starfleet S3 bucket that holds the account index JSON file
Value: !Ref AccountIndexBucket
AccountIndexGeneratorQueue:
Description: The Queue URL for the Account Index Generator invocation queue
Value: !GetAtt AccountIndexGeneratorQueue.QueueUrl
AccountIndexGeneratorDLQ:
Description: The Queue URL for the Account Index Generator invocation DLQ
Value: !GetAtt AccountIndexGeneratorDLQ.QueueUrl
AccountIndexGeneratorFunction:
Description: The Account Index Generator worker ship function that generates an account index
Value: !GetAtt AccountIndexGenerator.Arn
# Uncomment for the AWS Config worker:
# AWSConfigWorkerQueue:
# Description: The Queue URL for the AWS Config Worker invocation queue
# Value: !GetAtt AWSConfigWorkerQueue.QueueUrl
# AWSConfigWorkerDLQ:
# Description: The Queue URL for the AWS Config Worker invocation DLQ
# Value: !GetAtt AWSConfigWorkerDLQ.QueueUrl
# AWSConfigWorker:
# Description: The AWS Config Worker ship function that enables AWS Config everywhere
# Value: !GetAtt AWSConfigWorker.Arn
# Uncomment for the GitHub Sync worker:
# GitHubSyncWorkerQueue:
# Description: The Queue URL for the GitHub Sync Worker invocation queue
# Value: !GetAtt GitHubSyncWorkerQueue.QueueUrl
# GitHubSyncWorkerDLQ:
# Description: The Queue URL for the GitHub Sync Worker invocation DLQ
# Value: !GetAtt GitHubSyncWorkerDLQ.QueueUrl
# GitHubSyncWorker:
# Description: The GitHub Sync Worker ship function that syncs a GitHub repo with S3
# Value: !GetAtt GitHubSyncWorker.Arn
# Uncomment for the IAM Role worker:
# IamRoleWorkerQueue:
# Description: The Queue URL for the IAM Role Worker invocation queue
# Value: !GetAtt IamRoleWorkerQueue.QueueUrl
# IamRoleWorkerDLQ:
# Description: The Queue URL for the IAM Role Worker invocation DLQ
# Value: !GetAtt IamRoleWorkerDLQ.QueueUrl
# IamRoleWorker:
# Description: The IAM Role Worker ship function that uses iambic to sync IAM roles in our infrastructure
# Value: !GetAtt IamRoleWorker.Arn