-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
618 lines (598 loc) · 22.6 KB
/
Copy pathtemplate.yaml
File metadata and controls
618 lines (598 loc) · 22.6 KB
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Serverless Code Review Agents — Two-tier event-driven architecture.
EventBridge coordinates two Durable Function pipelines:
DF1 (Analysis): clone → security + style agents in parallel → severity scorer
DF2 (Remediation): Kiro headless auto-fix → test generation → executive summary
S3 Files provides a shared POSIX workspace across all functions.
# ════════════════════════════════════════════════════════════════
# Globals
# ════════════════════════════════════════════════════════════════
Globals:
Function:
Runtime: python3.14
MemorySize: 1024
Timeout: 900
Architectures:
- arm64
Tracing: Active
Environment:
Variables:
WORKSPACE_MOUNT: /mnt/workspace
# ════════════════════════════════════════════════════════════════
# Parameters
# ════════════════════════════════════════════════════════════════
Parameters:
BedrockModelId:
Type: String
Default: eu.anthropic.claude-sonnet-4-20250514-v1:0
Description: Bedrock inference profile ID for the review agents
Resources:
# ════════════════════════════════════════════════════════════════
# Networking (nested stack)
# ════════════════════════════════════════════════════════════════
NetworkingStack:
Type: AWS::Serverless::Application
Properties:
Location: stacks/network.yaml
# ════════════════════════════════════════════════════════════════
# S3 Files — shared workspace
# ════════════════════════════════════════════════════════════════
WorkspaceBucket:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
S3FilesRole:
Type: AWS::IAM::Role
Properties:
Path: /service-role/
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AllowS3FilesAssumeRole
Effect: Allow
Principal:
Service: elasticfilesystem.amazonaws.com
Action: sts:AssumeRole
Condition:
StringEquals:
aws:SourceAccount: !Ref AWS::AccountId
ArnLike:
aws:SourceArn: !Sub 'arn:aws:s3files:${AWS::Region}:${AWS::AccountId}:file-system/*'
Policies:
- PolicyName: S3FilesBucketAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: S3BucketPermissions
Effect: Allow
Action:
- s3:ListBucket*
Resource: !GetAtt WorkspaceBucket.Arn
Condition:
StringEquals:
aws:ResourceAccount: !Ref AWS::AccountId
- Sid: S3ObjectPermissions
Effect: Allow
Action:
- s3:AbortMultipartUpload
- s3:DeleteObject*
- s3:GetObject*
- s3:List*
- s3:PutObject*
Resource: !Sub '${WorkspaceBucket.Arn}/*'
Condition:
StringEquals:
aws:ResourceAccount: !Ref AWS::AccountId
S3FileSystem:
Type: AWS::S3Files::FileSystem
Properties:
Bucket: !GetAtt WorkspaceBucket.Arn
RoleArn: !GetAtt S3FilesRole.Arn
AcceptBucketWarning: true
MountTargetA:
Type: AWS::S3Files::MountTarget
Properties:
FileSystemId: !GetAtt S3FileSystem.FileSystemId
SubnetId: !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
SecurityGroups:
- !GetAtt NetworkingStack.Outputs.MountTargetSGId
MountTargetB:
Type: AWS::S3Files::MountTarget
Properties:
FileSystemId: !GetAtt S3FileSystem.FileSystemId
SubnetId: !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
SecurityGroups:
- !GetAtt NetworkingStack.Outputs.MountTargetSGId
S3FilesAccessPoint:
Type: AWS::S3Files::AccessPoint
Properties:
FileSystemId: !GetAtt S3FileSystem.FileSystemId
PosixUser:
Uid: '1000'
Gid: '1000'
RootDirectory:
Path: /lambda
CreationPermissions:
OwnerUid: '1000'
OwnerGid: '1000'
Permissions: '755'
# ════════════════════════════════════════════════════════════════
# API Gateway
# Publishes review.requested event to the default EventBridge bus.
# Returns 202 immediately.
# ════════════════════════════════════════════════════════════════
CodeReviewApi:
Type: AWS::Serverless::Api
Properties:
Name: CodeReviewApi
StageName: Prod
DefinitionBody:
openapi: 3.0.1
info:
title: Code Review API
version: '2.0'
paths:
/review:
post:
summary: Start a code review
x-amazon-apigateway-integration:
type: aws
httpMethod: POST
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:events:action/PutEvents'
credentials: !GetAtt ApiGatewayRole.Arn
passthroughBehavior: never
requestTemplates:
application/json: |
#set($body = $input.json('$'))
{
"Entries": [
{
"Source": "code-review.api",
"DetailType": "review.requested",
"Detail": "{\"repo_url\": $input.json('$.repo_url')}"
}
]
}
responses:
default:
statusCode: 202
responseTemplates:
application/json: |
{
"status": "ACCEPTED",
"message": "Code review requested. Events will coordinate the pipeline."
}
responses:
'202':
description: Review accepted
ApiGatewayRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: PutEvents
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: events:PutEvents
Resource: !Sub 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/default'
# ════════════════════════════════════════════════════════════════
# DF1 — Analysis Pipeline
# Clone → Security + Style agents (parallel) → Severity Scorer
# Emits analysis.complete when done.
# Triggered by review.requested on the default bus (implicit event).
# ════════════════════════════════════════════════════════════════
AnalysisPipelineFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-analysis-pipeline
Handler: app.handler
CodeUri: src/analysis_pipeline/
MemorySize: 512
Timeout: 900
DurableConfig:
ExecutionTimeout: 3600
RetentionPeriodInDays: 7
AutoPublishAlias: live
Events:
ReviewRequested:
Type: EventBridgeRule
Properties:
Pattern:
source:
- code-review.api
detail-type:
- review.requested
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
SECURITY_AGENT_ARN: !GetAtt SecurityAgentFunction.Arn
STYLE_AGENT_ARN: !GetAtt StyleAgentFunction.Arn
SEVERITY_SCORER_ARN: !GetAtt SeverityScorerFunction.Arn
Policies:
- Version: '2012-10-17'
Statement:
- Sid: InvokeAgents
Effect: Allow
Action: lambda:InvokeFunction
Resource:
- !GetAtt SecurityAgentFunction.Arn
- !Sub '${SecurityAgentFunction.Arn}:*'
- !GetAtt StyleAgentFunction.Arn
- !Sub '${StyleAgentFunction.Arn}:*'
- !GetAtt SeverityScorerFunction.Arn
- !Sub '${SeverityScorerFunction.Arn}:*'
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: EmitEvents
Effect: Allow
Action: events:PutEvents
Resource: !Sub 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/default'
# Security agent — Strands agent for vulnerability scanning
SecurityAgentFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-security-agent
Handler: app.lambda_handler
CodeUri: src/security_agent/
Timeout: 600
MemorySize: 1024
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
BEDROCK_MODEL_ID: !Ref BedrockModelId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: InvokeBedrock
Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
- bedrock:Converse
- bedrock:ConverseStream
Resource: '*'
# Style agent — Strands agent for code quality review
StyleAgentFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-style-agent
Handler: app.lambda_handler
CodeUri: src/style_agent/
Timeout: 600
MemorySize: 1024
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
BEDROCK_MODEL_ID: !Ref BedrockModelId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: InvokeBedrock
Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
- bedrock:Converse
- bedrock:ConverseStream
Resource: '*'
# Severity scorer — scores and prioritizes security findings
SeverityScorerFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-severity-scorer
Handler: app.lambda_handler
CodeUri: src/severity_scorer_agent/
Timeout: 300
MemorySize: 1024
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
BEDROCK_MODEL_ID: !Ref BedrockModelId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: InvokeBedrock
Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
- bedrock:Converse
- bedrock:ConverseStream
Resource: '*'
# ════════════════════════════════════════════════════════════════
# DF2 — Remediation Pipeline
# Kiro headless auto-fix → Test generation → Executive summary
# Emits remediation.complete when done.
# Triggered by analysis.complete on the default bus (implicit event).
# ════════════════════════════════════════════════════════════════
RemediationPipelineFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-remediation-pipeline
Handler: app.handler
CodeUri: src/remediation_pipeline/
MemorySize: 512
Timeout: 900
DurableConfig:
ExecutionTimeout: 3600
RetentionPeriodInDays: 7
AutoPublishAlias: live
Events:
AnalysisComplete:
Type: EventBridgeRule
Properties:
Pattern:
source:
- code-review.analysis
detail-type:
- analysis.complete
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
KIRO_AGENT_ARN: !GetAtt KiroAutoFixFunction.Arn
TEST_GEN_AGENT_ARN: !GetAtt TestGenAgentFunction.Arn
SUMMARY_AGENT_ARN: !GetAtt ExecutiveSummaryFunction.Arn
Policies:
- Version: '2012-10-17'
Statement:
- Sid: InvokeAgents
Effect: Allow
Action: lambda:InvokeFunction
Resource:
- !GetAtt KiroAutoFixFunction.Arn
- !Sub '${KiroAutoFixFunction.Arn}:*'
- !GetAtt TestGenAgentFunction.Arn
- !Sub '${TestGenAgentFunction.Arn}:*'
- !GetAtt ExecutiveSummaryFunction.Arn
- !Sub '${ExecutiveSummaryFunction.Arn}:*'
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: EmitEvents
Effect: Allow
Action: events:PutEvents
Resource: !Sub 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/default'
# Kiro headless — auto-fix agent that reasons over the full codebase
KiroAutoFixFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-kiro-autofix
Handler: app.lambda_handler
CodeUri: src/kiro_autofix_agent/
Timeout: 900
MemorySize: 1024
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
BEDROCK_MODEL_ID: !Ref BedrockModelId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: InvokeBedrock
Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
- bedrock:Converse
- bedrock:ConverseStream
Resource: '*'
# Test generation agent — validates fixes with generated tests
TestGenAgentFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-test-gen-agent
Handler: app.lambda_handler
CodeUri: src/test_gen_agent/
Timeout: 600
MemorySize: 1024
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
BEDROCK_MODEL_ID: !Ref BedrockModelId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: InvokeBedrock
Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
- bedrock:Converse
- bedrock:ConverseStream
Resource: '*'
# Executive summary agent — fans-in all results into final report
ExecutiveSummaryFunction:
Type: AWS::Serverless::Function
DependsOn:
- MountTargetA
- MountTargetB
Properties:
FunctionName: code-review-executive-summary
Handler: app.lambda_handler
CodeUri: src/executive_summary_agent/
Timeout: 300
MemorySize: 1024
VpcConfig:
SecurityGroupIds:
- !GetAtt NetworkingStack.Outputs.LambdaSGId
SubnetIds:
- !GetAtt NetworkingStack.Outputs.PrivateSubnetAId
- !GetAtt NetworkingStack.Outputs.PrivateSubnetBId
FileSystemConfigs:
- Arn: !GetAtt S3FilesAccessPoint.AccessPointArn
LocalMountPath: /mnt/workspace
Environment:
Variables:
BEDROCK_MODEL_ID: !Ref BedrockModelId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: MountS3Files
Effect: Allow
Action:
- s3files:ClientMount
- s3files:ClientWrite
- s3files:ClientRootAccess
Resource: !GetAtt S3FileSystem.FileSystemArn
- Sid: InvokeBedrock
Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
- bedrock:Converse
- bedrock:ConverseStream
Resource: '*'
# ════════════════════════════════════════════════════════════════
# Outputs
# ════════════════════════════════════════════════════════════════
Outputs:
ApiEndpoint:
Description: POST a repo_url here to start a review
Value: !Sub 'https://${CodeReviewApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/review'
WorkspaceBucketName:
Description: S3 bucket — check {repo}/reviews/ for results
Value: !Ref WorkspaceBucket
S3FileSystemId:
Description: S3 file system ID
Value: !GetAtt S3FileSystem.FileSystemId