-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
6981 lines (6636 loc) · 254 KB
/
template.yaml
File metadata and controls
6981 lines (6636 loc) · 254 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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: AWS GenAI IDP Accelerator (uksb-r8evguc4p9) (SO9027) (v<VERSION>)
Mappings:
AppSyncLogLevelMap:
DEBUG:
FieldLogLevel: ALL
INFO:
FieldLogLevel: ALL
WARN:
FieldLogLevel: ERROR
ERROR:
FieldLogLevel: ERROR
CRITICAL:
FieldLogLevel: ERROR
CrawlerScheduleMap:
Manual:
ScheduleExpression: ""
Every15m:
ScheduleExpression: "cron(0/15 * * * ? *)"
EveryHour:
ScheduleExpression: "cron(0 * * * ? *)"
EveryDay:
ScheduleExpression: "cron(0 0 * * ? *)"
Pattern1ConfigurationMap:
lending-package-sample:
ConfigPath: "lending-package-sample"
docsplit:
ConfigPath: "docsplit"
realkie-fcc-verified:
ConfigPath: "realkie-fcc-verified"
ocr-benchmark:
ConfigPath: "ocr-benchmark"
rvl-cdip:
ConfigPath: "rvl-cdip"
default:
ConfigPath: "lending-package-sample"
Pattern2ConfigurationMap:
lending-package-sample:
ConfigPath: "lending-package-sample"
rvl-cdip:
ConfigPath: "rvl-cdip"
rvl-cdip-with-few-shot-examples:
ConfigPath: "rvl-cdip-with-few-shot-examples"
bank-statement-sample:
ConfigPath: "bank-statement-sample"
docsplit:
ConfigPath: "docsplit"
realkie-fcc-verified:
ConfigPath: "realkie-fcc-verified"
ocr-benchmark:
ConfigPath: "ocr-benchmark"
rule-validation:
ConfigPath: "rule-validation"
rule-extraction:
ConfigPath: "rule-extraction"
default:
ConfigPath: "rvl-cdip"
Pattern3ConfigurationMap:
rvl-cdip:
ConfigPath: "rvl-cdip"
rvl-cdip-package-sample: # for backward compatibility when updating existing stacks
ConfigPath: "rvl-cdip"
default:
ConfigPath: "rvl-cdip"
Parameters:
# Authorization params
AdminEmail:
Type: String
Description: >-
Email address of the admin user (e.g. jdoe+admin@example.com).
An initial temporary password is automatically sent to this user via email.
AllowedPattern: '^[\w.+-]+@([\w-]+\.)+[\w-]{2,6}$'
AllowedSignUpEmailDomain:
Type: String
Default: ""
Description: >-
Email address domain (example.com) or comma separated list of email domains (example1.com,
example2.com) allowed to signup using the web UI.
If left empty, signup via the web UI is disabled and users will have to be created
using Cognito.
AllowedPattern: '^(|([\w-]+\.)+[\w-]{2,6}(, *([\w-]+\.)+[\w-]{2,6})*)$'
ConstraintDescription: >-
Must be empty or a list of comma separated email domains (example1.com, example2.com)
# Pattern selection
IDPPattern:
Type: String
Default: Pattern1 - Packet or Media processing with Bedrock Data Automation (BDA)
AllowedValues:
- Pattern1 - Packet or Media processing with Bedrock Data Automation (BDA)
- Pattern2 - Packet processing with Textract and Bedrock
- Pattern3 - Packet processing with Textract, SageMaker(UDOP), and Bedrock
Description: >-
Built-in IDP workflow patterns - see README for pattern descriptions.
# Custom Configuration Path
CustomConfigPath:
Type: String
Default: ""
Description: >-
S3 URI pointing to your custom configuration YAML file. When provided, this configuration overrides the selected pattern preset and applies to all processing patterns.
Leave blank to use the selected pattern configuration preset. For example s3://my-bucket/custom-config/config.yaml
AllowedPattern: '^(|s3://.*)$'
ConstraintDescription: Must be empty or a valid S3 URI (e.g., s3://my-bucket/custom-config/config.yaml)
# Pattern 1 Parameters
Pattern1BDAProjectArn:
Type: String
Default: ""
AllowedPattern: "^(|^arn:aws[a-z-]*:bedrock:[a-z0-9-]+:.+:data-automation-project/.+)$"
Description: For Pattern-1, provide a Bedrock Data Automation (BDA) project ARN, or leave blank to create a sample project for processing the sample lending package.
Pattern1Configuration:
Type: String
Default: "lending-package-sample"
AllowedValues:
- "lending-package-sample"
- "docsplit"
- "realkie-fcc-verified"
- "ocr-benchmark"
- "rvl-cdip"
- "default"
Description: >-
Select the configuration preset for Pattern 1. Each configuration contains pre-tuned settings for specific document processing scenarios - see https://github.com/aws-samples/sample-genai-idp/blob/main/config_library/README.md. Note: This selected configuration will be replaced by the Custom Configuration Path if specified.
# Pattern 2 Parameters
Pattern2Configuration:
Type: String
Default: "lending-package-sample"
AllowedValues:
- "lending-package-sample"
- "rvl-cdip"
- "rvl-cdip-with-few-shot-examples"
- "bank-statement-sample"
- "docsplit"
- "realkie-fcc-verified"
- "ocr-benchmark"
- "rule-validation"
- "rule-extraction"
- "default"
Description: >-
Select the configuration preset for Pattern 2. Each configuration contains pre-tuned settings for specific document processing scenarios see https://github.com/aws-samples/sample-genai-idp/blob/main/config_library/README.md. Note: Custom configuration overrides the selected pattern configuration when provided.
Pattern2CustomClassificationModelARN:
Type: String
Default: ""
Description: Specify Custom Fine Tuned Classification Model ARN. Leave blank to use pretrained model specified in the selected configuration.
Pattern2CustomExtractionModelARN:
Type: String
Default: ""
Description: Specify Custom Fine Tuned Extraction Model ARN. Leave blank to use pretrained model specified in the selected configuration.
Pattern3UDOPModelArtifactPath:
Type: String
Default: "<PUBLIC_SAMPLE_UDOP_MODEL>"
AllowedPattern: "^(|s3://.*)$"
Description: For Pattern-3, provide S3 path to the UDOP model.tar.gz file (e.g., s3://bucket-name/path/to/model.tar.gz)
Pattern3Configuration:
Type: String
Default: "rvl-cdip"
AllowedValues:
- "rvl-cdip"
- "default"
- "rvl-cdip-package-sample" # for backward compatibility when updating existing stacks
Description: >-
Select the configuration preset for Pattern 3. Each configuration contains pre-tuned settings for specific document processing scenarios - see https://github.com/aws-samples/sample-genai-idp/blob/main/config_library/README.md. Note: Custom configuration overrides the selected pattern configuration when provided.
# Evaluation
EvaluationBaselineBucketName:
Type: String
Default: ""
Description: >-
(Optional) Existing bucket used for baseline (ground truth) data for processed documents. Baseline data is used to asess the accuracy
of the processing pattern outputs.
Provide the name of an existing bucket here. Hint: you can use the Output bucket of another GenAIIDP stack to compare the outputs from
different patterns and prompts.
Leave blank to automatically create an empty bucket where you can (optionally) place your validated baseline data later.
ReportingBucketName:
Type: String
Default: ""
Description: >-
(Optional) Existing bucket used for analytics. (Currently used for evaluation analytics)
Provide the name of an existing bucket here or leave blank to automatically create a new bucket.
DocumentSectionsCrawlerFrequency:
Type: String
Default: "EveryDay"
AllowedValues:
- "Manual"
- "Every15m"
- "EveryHour"
- "EveryDay"
Description: >-
Frequency for the Glue Crawler to run and discover new document section tables and partitions.
Manual requires manual execution, other options run automatically at the specified interval.
# X-Ray Tracing
EnableXRayTracing:
Type: String
Default: 'true'
AllowedValues: [ 'true', 'false' ]
Description: Enable X-Ray tracing
# MCP Integration
EnableMCP:
Type: String
Default: 'true'
AllowedValues: [ 'true', 'false' ]
Description: Enable Model Context Protocol (MCP) integration for external application access via AWS Bedrock AgentCore Gateway
# Optional Knowledge Base Configuration
DocumentKnowledgeBase:
Default: "BEDROCK_KNOWLEDGE_BASE (Create)"
Type: String
AllowedValues:
- "DISABLED"
- "BEDROCK_KNOWLEDGE_BASE (Create)"
Description: Use document processing results as knowledge base content. Model access for amazon.titan-embed-text-v2:0 MUST be enabled in Amazon Bedrock.
KnowledgeBaseVectorStore:
Type: String
Default: "S3_VECTORS"
AllowedValues:
- "OPENSEARCH_SERVERLESS"
- "S3_VECTORS"
Description: Choose vector store type for Bedrock Knowledge Base. S3 Vectors (default) for cost-effective storage with sub-second latency, OpenSearch Serverless for sub-millisecond queries.
KnowledgeBaseModelId:
Type: String
Default: "us.amazon.nova-pro-v1:0"
AllowedValues:
- "us.amazon.nova-lite-v1:0"
- "us.amazon.nova-pro-v1:0"
- "us.amazon.nova-premier-v1:0"
- "us.amazon.nova-2-lite-v1:0"
- "us.amazon.nova-2-lite-v1:0:priority"
- "us.amazon.nova-2-lite-v1:0:flex"
- "global.amazon.nova-2-lite-v1:0"
- "global.amazon.nova-2-lite-v1:0:priority"
- "global.amazon.nova-2-lite-v1:0:flex"
- "us.anthropic.claude-3-haiku-20240307-v1:0"
- "us.anthropic.claude-3-5-haiku-20241022-v1:0"
- "us.anthropic.claude-3-5-sonnet-20241022-v2:0"
- "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
- "us.anthropic.claude-sonnet-4-20250514-v1:0"
- "us.anthropic.claude-sonnet-4-5-20250929-v1:0"
- "eu.amazon.nova-lite-v1:0"
- "eu.amazon.nova-pro-v1:0"
- "eu.amazon.nova-2-lite-v1:0"
- "eu.amazon.nova-2-lite-v1:0:priority"
- "eu.amazon.nova-2-lite-v1:0:flex"
- "eu.anthropic.claude-3-haiku-20240307-v1:0"
- "eu.anthropic.claude-3-5-sonnet-20241022-v2:0"
- "eu.anthropic.claude-3-7-sonnet-20250219-v1:0"
- "eu.anthropic.claude-sonnet-4-20250514-v1:0"
- "eu.anthropic.claude-sonnet-4-5-20250929-v1:0"
- "qwen.qwen3-vl-235b-a22b"
- "global.amazon.nova-2-lite-v1:0"
- "global.anthropic.claude-haiku-4-5-v1:0"
- "global.anthropic.claude-sonnet-4-5-v1:0"
Description: Model to use for optional Document Knowledge Base. Model access MUST be enabled in Amazon Bedrock. Note - Nova Premier may not be available in all EU regions.
# Optional - Post processing Lambda hook
PostProcessingLambdaHookFunctionArn:
Default: ""
Type: String
AllowedPattern: "^(|arn:aws[a-z-]*:lambda:.*)$"
Description: >
(Optional) The specified Lambda function is invoked by EventBridge after the document processing workflow is processed.
This function can implement custom logic to initiate downstream processing on the output of the processing pattern.
# Optional Bedrock Guardrail Configuration
BedrockGuardrailId:
Type: String
Default: ""
AllowedPattern: "^(|[a-z0-9]+)$"
Description: >
Optionally provide the *Id* (not name) of an *existing* Bedrock Guardrail (looks like: wxyz3ab12x34) to be used for all Bedrock and Bedrock Knowledge Base interactions.
BedrockGuardrailVersion:
Type: String
Default: "DRAFT"
AllowedPattern: "^(|(([1-9][0-9]{0,7})|(DRAFT)))$"
Description: >
If you provided a Bedrock Guardrail Id above, provide the corresponding Guardrail version here (e.g. DRAFT|1|2|...).
# General Configuration
MaxConcurrentWorkflows:
Type: Number
Default: 100
Description: Maximum number of concurrent workflow executions allowed
MinValue: 1
DataRetentionInDays:
Type: Number
Default: 365
Description: Number of days to retain documents (S3) and tracking records (DynamoDB)
MinValue: 1
ErrorThreshold:
Type: Number
Default: 1
Description: Number of workflow errors that triggers an alert (per 5 minutes)
MinValue: 1
ExecutionTimeThresholdMs:
Type: Number
Default: 300000
Description: Maximum acceptable execution time in milliseconds before alerting (default 300000 = 300 seconds)
MinValue: 1000
# Security Configuration
PermissionsBoundaryArn:
Type: String
Default: ""
Description: >-
(Optional) ARN of an existing IAM Permissions Boundary policy to attach to all IAM roles.
Required by some organizations with Service Control Policies (SCPs).
Format: arn:partition:iam::account-id:policy/policy-name
Leave blank if no Permissions Boundary is required.
AllowedPattern: "^(|arn:aws[a-z-]*:iam::[0-9]{12}:policy/.+)$"
ConstraintDescription: Must be empty or a valid IAM policy ARN
EnableECRImageScanning:
Type: String
Default: "false"
AllowedValues:
- "true"
- "false"
Description: >-
Enable automatic vulnerability scanning for Lambda container images in ECR (applies to Pattern-1 and Pattern-2).
Disabling may improve deployment reliability but reduces security posture.
Recommended: true for production, false only if experiencing deployment issues.
# Logging configuration
LogLevel:
Type: String
Default: INFO
AllowedValues:
- DEBUG
- INFO
- WARN
- ERROR
Description: Default logging level for all logs
LogRetentionDays:
Type: Number
Default: 30
Description: Number of days to retain CloudWatch logs
AllowedValues:
[
1,
3,
5,
7,
14,
30,
60,
90,
120,
150,
180,
365,
400,
545,
731,
1827,
3653,
]
CloudFrontPriceClass:
Type: String
Default: PriceClass_100
Description: >-
Specify the CloudFront price class. See https://aws.amazon.com/cloudfront/pricing/
for a
description of each price class.
AllowedValues:
- PriceClass_100
- PriceClass_200
- PriceClass_All
ConstraintDescription: >-
Allowed Price Classes PriceClass_100 PriceClass_200 and PriceClass_All
CloudFrontAllowedGeos:
Type: String
Default: ""
Description: >-
Specify a comma separated list of two letter country codes (uppercase ISO 3166-1)
that are
allowed to access the web user interface via CloudFront. For example: US,CA.
Leave empty if
you do not want geo restrictions to be applied.
AllowedPattern: "^(|[A-Z]{2}(,[A-Z]{2})*)$"
ConstraintDescription: >-
Comma separated list of uppercase two letter country codes or empty
WAFAllowedIPv4Ranges:
Type: String
Default: "0.0.0.0/0"
Description: >-
Comma-separated list of IPv4 CIDR ranges to allow. Default (0.0.0.0/0) disables WAF and allows all IPs.
Example to restrict: "192.168.1.0/24, 10.0.0.0/16"
AllowedPattern: '^([0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]{1,2}(,\s*([0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]{1,2})*$'
ConstraintDescription: Must be valid comma-separated list of IPv4 CIDR ranges
Rules:
Pattern3UDOPModelArtifactPath:
RuleCondition:
!Equals [
!Ref IDPPattern,
"Pattern3 - Packet processing with Textract, SageMaker(UDOP), and Bedrock",
]
Assertions:
- Assert: !Not [ !Equals [ !Ref Pattern3UDOPModelArtifactPath, "" ] ]
AssertDescription: UDOP Model Artifact Path is required when IDPPattern is 'Pattern1'
Conditions:
IsPattern1:
!Equals [
!Ref IDPPattern,
"Pattern1 - Packet or Media processing with Bedrock Data Automation (BDA)",
]
IsPattern2:
!Equals [
!Ref IDPPattern,
"Pattern2 - Packet processing with Textract and Bedrock",
]
IsPattern3:
!Equals [
!Ref IDPPattern,
"Pattern3 - Packet processing with Textract, SageMaker(UDOP), and Bedrock",
]
ShouldCreateBDASampleProject:
!And [ !Condition IsPattern1, !Equals [ !Ref Pattern1BDAProjectArn, "" ] ]
HasPattern1BDAProjectArn:
!Not [ !Equals [ !Ref Pattern1BDAProjectArn, "" ] ]
HasGuardrailConfig:
!And [
!Not [ !Equals [ !Ref BedrockGuardrailId, "" ] ],
!Not [ !Equals [ !Ref BedrockGuardrailVersion, "" ] ],
]
# HITL and Private Workforce conditions
# General rules
ShouldAllowSignUpEmailDomain:
!Not [ !Equals [ !Ref AllowedSignUpEmailDomain, "" ] ]
ShouldEnableGeoRestriction: !Not [ !Equals [ !Ref CloudFrontAllowedGeos, "" ] ]
ShouldEnablePostProcessingLambdaHook:
!Not [ !Equals [ !Ref PostProcessingLambdaHookFunctionArn, "" ] ]
ShouldCreateEvaluationBaselineBucket:
!Equals [ !Ref EvaluationBaselineBucketName, "" ]
ShouldCreateReportingBucket: !Equals [ !Ref ReportingBucketName, "" ]
IsWafEnabled: !Not [ !Equals [ !Ref WAFAllowedIPv4Ranges, "0.0.0.0/0" ] ]
ShouldCreateDocumentKnowledgeBase:
!Equals [ !Ref DocumentKnowledgeBase, "BEDROCK_KNOWLEDGE_BASE (Create)" ]
ShouldUseDocumentKnowledgeBase: !Condition ShouldCreateDocumentKnowledgeBase
DocumentSectionsCrawlerScheduleEnabled:
!Not [ !Equals [ !Ref DocumentSectionsCrawlerFrequency, "Manual" ] ]
HasPermissionsBoundary: !Not [ !Equals [ !Ref PermissionsBoundaryArn, "" ] ]
HasCustomConfigPath: !Not [ !Equals [ !Ref CustomConfigPath, "" ] ]
IsS3VectorsVectorStore: !Equals [ !Ref KnowledgeBaseVectorStore, "S3_VECTORS" ]
CreateAgentCoreLambda: !Equals [ !Ref EnableMCP, "true" ]
CreateExternalAppClient: !Equals [ !Ref EnableMCP, "true" ]
Metadata:
cfn-lint:
config:
ignore_checks:
- W1030 # ARN pattern matching when Ref resolves to empty string
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "User Authentication"
Parameters:
- AdminEmail
- AllowedSignUpEmailDomain
- Label:
default: "Workflow Pattern Selection"
Parameters:
- IDPPattern
- Label:
default: "Pattern 1 Configuration"
Parameters:
- Pattern1Configuration
- Pattern1BDAProjectArn
- Label:
default: "Pattern 2 Configuration"
Parameters:
- Pattern2Configuration
- Pattern2CustomClassificationModelARN
- Pattern2CustomExtractionModelARN
- Label:
default: "Pattern 3 Configuration"
Parameters:
- Pattern3Configuration
- Pattern3UDOPModelArtifactPath
- Label:
default: "Custom Configuration"
Parameters:
- CustomConfigPath
- Label:
default: "Evaluation"
Parameters:
- EvaluationBaselineBucketName
- Label:
default: "Reporting"
Parameters:
- ReportingBucketName
- DocumentSectionsCrawlerFrequency
- Label:
default: "Document Knowledge Base"
Parameters:
- DocumentKnowledgeBase
- KnowledgeBaseVectorStore
- KnowledgeBaseModelId
- Label:
default: "Post Processing"
Parameters:
- PostProcessingLambdaHookFunctionArn
- Label:
default: "Bedrock Guardrails"
Parameters:
- BedrockGuardrailId
- BedrockGuardrailVersion
- Label:
default: "Security Configuration"
Parameters:
- PermissionsBoundaryArn
- WAFAllowedIPv4Ranges
- Label:
default: "MCP Integration"
Parameters:
- EnableMCP
- Label:
default: "General Configuration"
Parameters:
- MaxConcurrentWorkflows
- DataRetentionInDays
- ErrorThreshold
- ExecutionTimeThresholdMs
- LogLevel
- LogRetentionDays
- CloudFrontPriceClass
- CloudFrontAllowedGeos
ParameterLabels:
AdminEmail:
default: "Admin Email Address"
AllowedSignUpEmailDomain:
default: "Allowed Sign Up Email Domain"
IDPPattern:
default: "Document Processing Pattern"
Pattern1BDAProjectArn:
default: "Pattern1 - Packet or Media processing with Bedrock Data Automation (BDA) Project ARN"
Pattern2CustomClassificationModelARN:
default: "Pattern2 - Custom Classification Model ARN"
Pattern2CustomExtractionModelARN:
default: "Pattern2 - Custom Extraction Model ARN"
Pattern1Configuration:
default: "Pattern1 - Configuration Preset"
Pattern2Configuration:
default: "Pattern2 - Configuration Preset"
Pattern3UDOPModelArtifactPath:
default: "Pattern3 - UDOP Model Artifact Path"
Pattern3Configuration:
default: "Pattern3 - Configuration Preset"
CustomConfigPath:
default: "Custom Configuration Path"
PostProcessingLambdaHookFunctionArn:
default: "Post Processing Lambda Hook Function ARN"
EvaluationBaselineBucketName:
default: "Evaluation Baseline Bucket Name"
ReportingBucketName:
default: "Reporting Bucket Name"
DocumentKnowledgeBase:
default: "Document Knowledge Base Configuration"
KnowledgeBaseModelId:
default: "Knowledge Base Model Id"
BedrockGuardrailId:
default: "Bedrock Guardrail Id"
BedrockGuardrailVersion:
default: "Bedrock Guardrail Version"
PermissionsBoundaryArn:
default: "Permissions Boundary ARN"
MaxConcurrentWorkflows:
default: "Maximum Concurrent Workflows"
DataRetentionInDays:
default: "Data Retention Period (days)"
ErrorThreshold:
default: "Error Alert Threshold"
ExecutionTimeThresholdMs:
default: "Execution Time Threshold (ms)"
LogLevel:
default: "Logging Level"
LogRetentionDays:
default: "Log Retention Period (days)"
CloudFrontPriceClass:
default: "CloudFront Price Class"
CloudFrontAllowedGeos:
default: "CloudFront Allowed Geos"
WAFAllowedIPv4Ranges:
default: "WAF Allowed IPv4 Ranges"
EnableMCP:
default: "Enable MCP Integration"
Resources:
# Custom resource to enforce max length of StackName - prevent downstream failures
StacknameCheckFunction:
Type: AWS::Serverless::Function
Metadata:
cfn_nag:
rules_to_suppress:
- id: W89
reason: Function does not require VPC access as it has no network access
- id: W92
reason: Reserved concurrency not required
# checkov:skip=CKV_AWS_116: "DLQ not required for Cfn Custom Resource function"
# checkov:skip=CKV_AWS_117: "Function does not require VPC access as it only interacts with AWS services via APIs"
# checkov:skip=CKV_AWS_115: "Function does not require reserved concurrency as it scales based on demand"
# checkov:skip=CKV_AWS_173: "Environment variables do not contain sensitive data - only configuration values like feature flags and non-sensitive settings"
Properties:
PermissionsBoundary:
!If [
HasPermissionsBoundary,
!Ref PermissionsBoundaryArn,
!Ref AWS::NoValue,
]
Handler: index.handler
Runtime: python3.12
InlineCode: |
import cfnresponse
import time
import json
def handler(event, context):
print(json.dumps(event))
input = event['ResourceProperties'].get('InputString', '')
max_length = int(event['ResourceProperties'].get('MaxLength', 0))
status = cfnresponse.SUCCESS
reason = f"Stack Name Length under {max_length} - OK"
if event['RequestType'] == "Create":
if len(input) > max_length:
status = cfnresponse.FAILED
reason = f"Stack Name ({input}) length ({len(input)}) too long - max length {max_length} - FAILED"
else:
print(f"Request type is {event['RequestType']} - skipping")
cfnresponse.send(event, context, status, {}, reason=reason)
Environment:
Variables:
LOG_LEVEL: INFO
LoggingConfig:
LogGroup:
Ref: StacknameCheckFunctionLogGroup
StacknameCheckFunctionLogGroup:
Metadata:
cfn_nag:
rules_to_suppress:
- id: W84
reason: "LogGroup does not require KMS Key Id, since it's only logging checks on stack name length"
# checkov:skip=CKV_AWS_158: "LogGroup does not require KMS Key Id, since it's only logging checks on stack name length"
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: !Ref LogRetentionDays
IsStacknameLengthOK:
Type: Custom::StacknameCheck
Properties:
ServiceToken: !GetAtt StacknameCheckFunction.Arn
InputString: !Ref "AWS::StackName"
MaxLength: 25
ConfigurationCopyFunction:
Type: AWS::Serverless::Function
Metadata:
cfn_nag:
rules_to_suppress:
- id: W89
reason: Function does not require VPC access as it only interacts with S3
- id: W92
reason: Reserved concurrency not required
# checkov:skip=CKV_AWS_116: "DLQ not required for Cfn Custom Resource function"
# checkov:skip=CKV_AWS_117: "Function does not require VPC access as it only interacts with AWS services via APIs"
# checkov:skip=CKV_AWS_115: "Function does not require reserved concurrency as it scales based on demand"
# checkov:skip=CKV_AWS_173: "Environment variables do not contain sensitive data - only configuration values like feature flags and non-sensitive settings"
Properties:
PermissionsBoundary:
!If [
HasPermissionsBoundary,
!Ref PermissionsBoundaryArn,
!Ref AWS::NoValue,
]
Handler: index.handler
Runtime: python3.12
Timeout: 300
InlineCode: |
import boto3
import cfnresponse
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def handler(event, context):
logger.info(json.dumps(event))
try:
source_bucket = event['ResourceProperties']['SourceBucket']
source_prefix = event['ResourceProperties']['SourcePrefix']
target_bucket = event['ResourceProperties']['TargetBucket']
target_prefix = event['ResourceProperties'].get('TargetPrefix', '')
file_list = event['ResourceProperties'].get('FileList', [])
s3_client = boto3.client('s3')
if event['RequestType'] == 'Create' or event['RequestType'] == 'Update':
# Copy files explicitly from the provided list
copied_count = 0
for relative_file_path in file_list:
# Skip empty entries
if not relative_file_path.strip():
continue
# Construct source key
source_key = f"{source_prefix}/{relative_file_path}"
# Construct target key with optional target prefix
if target_prefix:
target_key = f"{target_prefix}/{relative_file_path}"
else:
target_key = relative_file_path
logger.info(f"Copying {source_bucket}/{source_key} to {target_bucket}/{target_key}")
try:
copy_source = {'Bucket': source_bucket, 'Key': source_key}
s3_client.copy_object(
CopySource=copy_source,
Bucket=target_bucket,
Key=target_key
)
copied_count += 1
except Exception as copy_error:
logger.warning(f"Failed to copy {source_key}: {str(copy_error)}")
# Continue with other files instead of failing the entire operation
logger.info(f"Successfully copied {copied_count} configuration files")
cfnresponse.send(event, context, cfnresponse.SUCCESS, {
'CopiedFiles': copied_count
}, reason=f"Successfully copied {copied_count} configuration files")
elif event['RequestType'] == 'Delete':
# For delete, we don't need to clean up the configuration files
# as they may be needed by other resources
logger.info("Delete request - no action needed for configuration files")
cfnresponse.send(event, context, cfnresponse.SUCCESS, {},
reason="Delete completed - configuration files retained")
except Exception as e:
logger.error(f"Error: {str(e)}")
cfnresponse.send(event, context, cfnresponse.FAILED, {},
reason=f"Error copying configuration files: {str(e)}")
Environment:
Variables:
LOG_LEVEL: INFO
LoggingConfig:
LogGroup:
Ref: ConfigurationCopyFunctionLogGroup
Policies:
- S3ReadPolicy:
BucketName: "<ARTIFACT_BUCKET_TOKEN>"
- S3WritePolicy:
BucketName: !Ref ConfigurationBucket
- Statement:
- Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:DescribeKey
Resource: !GetAtt CustomerManagedEncryptionKey.Arn
ConfigurationCopyFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: !Ref LogRetentionDays
KmsKeyId: !GetAtt CustomerManagedEncryptionKey.Arn
CopyConfigurationFiles:
Type: Custom::ConfigurationCopy
Properties:
ServiceToken: !GetAtt ConfigurationCopyFunction.Arn
SourceBucket: "<ARTIFACT_BUCKET_TOKEN>"
SourcePrefix: "<ARTIFACT_PREFIX_TOKEN>/config_library"
TargetBucket: !Ref ConfigurationBucket
TargetPrefix: "config_library"
ConfigLibraryHash: "<CONFIG_LIBRARY_HASH_TOKEN>"
FileList: <CONFIG_FILES_LIST_TOKEN>
##########################################################################
# Nested stack for selected options
##########################################################################
BDASAMPLEPROJECT:
DependsOn:
- IsStacknameLengthOK
Type: AWS::CloudFormation::Stack
Condition: ShouldCreateBDASampleProject
Properties:
TemplateURL: ./nested/bda-lending-project/.aws-sam/packaged.yaml
Parameters:
ProjectName: !Sub "${AWS::StackName}-BDA-Lending-Sample-Project"
ProjectDescription: !Sub "${AWS::StackName}-BDA-Lending-Sample-Project"
LogLevel: !Ref LogLevel
PermissionsBoundaryArn: !Ref PermissionsBoundaryArn
DOCUMENTKB:
DependsOn:
- IsStacknameLengthOK
Type: AWS::CloudFormation::Stack
Condition: ShouldCreateDocumentKnowledgeBase
Properties:
TemplateURL: ./nested/bedrockkb/.aws-sam/packaged.yaml
Parameters:
pKnowledgeBaseBucketName: !Ref OutputBucket
pInputDocumentUploadFolderPrefix: ""
pS3SyncScheduleExpression: "cron(0/30 * ? * * *)" # default is to sync documents every 30 minutes
pCustomerManagedEncryptionKeyArn: !GetAtt CustomerManagedEncryptionKey.Arn
pChunkingStrategy: "Fixed-size chunking"
pMaxTokens: 8192
pVectorStoreType: !Ref KnowledgeBaseVectorStore
LogLevel: !Ref LogLevel
PermissionsBoundaryArn: !Ref PermissionsBoundaryArn
##########################################################################
# AgentCore Analytics Lambda Function
##########################################################################
AgentCoreAnalyticsLambdaLogGroup:
Type: AWS::Logs::LogGroup
Condition: CreateAgentCoreLambda
Properties:
KmsKeyId: !GetAtt CustomerManagedEncryptionKey.Arn
RetentionInDays: !Ref LogRetentionDays
AgentCoreAnalyticsLambdaFunction:
Type: AWS::Serverless::Function
Condition: CreateAgentCoreLambda
Metadata:
cfn_nag:
rules_to_suppress:
- id: W89
reason: "Function does not require VPC access as it only interacts with AWS services via APIs"
- id: W92
reason: "Function does not require reserved concurrency as it scales based on demand"
# checkov:skip=CKV_AWS_116: "DLQ not required for AgentCore analytics function"
# checkov:skip=CKV_AWS_117: "Function does not require VPC access as it only interacts with AWS services via APIs"
# checkov:skip=CKV_AWS_115: "Function does not require reserved concurrency as it scales based on demand"
# checkov:skip=CKV_AWS_173: "Environment variables do not contain sensitive data - only configuration values like feature flags and non-sensitive settings"
Properties:
FunctionName: !Sub "${AWS::StackName}-agentcore-analytics"
CodeUri: src/lambda/agentcore_analytics_processor/
Handler: index.lambda_handler
Runtime: python3.12
MemorySize: 1024
Timeout: 900
Layers:
- !Ref IDPCommonAgentsLayer
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
CONFIGURATION_TABLE_NAME: !Ref ConfigurationTable
TRACKING_TABLE_NAME: !Ref TrackingTable
LOOKUP_FUNCTION_NAME: !Ref LookupFunction
STRANDS_LOG_LEVEL: !Ref LogLevel
AGENT_TABLE: !Ref AgentTable
APPSYNC_API_URL: !GetAtt GraphQLApi.GraphQLUrl
ATHENA_DATABASE: !Ref ReportingDatabase
ATHENA_WORKGROUP: primary
QUERY_RESULTS_BUCKET: !If
- ShouldCreateReportingBucket
- !Ref ReportingBucket
- !Ref ReportingBucketName
ATHENA_OUTPUT_LOCATION: !Sub
- "s3://${Bucket}/athena-results/"
- Bucket: !If
- ShouldCreateReportingBucket
- !Ref ReportingBucket
- !Ref ReportingBucketName
AWS_STACK_NAME: !Ref AWS::StackName
GUARDRAIL_ID_AND_VERSION:
!If [
HasGuardrailConfig,
!Sub "${BedrockGuardrailId}:${BedrockGuardrailVersion}",
"",
]
CLOUDWATCH_LOG_GROUP_PREFIX: !Sub "/aws/lambda/${AWS::StackName}"
SETTINGS_PARAMETER_NAME: !Ref SettingsParameter
LoggingConfig:
LogGroup: !Ref AgentCoreAnalyticsLambdaLogGroup
Policies:
- Statement:
Effect: Allow
Action: bedrock-agentcore:InvokeAgentRuntime
Resource: "*"
- Statement:
Effect: Allow
Action: appsync:GraphQL
Resource: !Sub "arn:${AWS::Partition}:appsync:${AWS::Region}:${AWS::AccountId}:apis/${GraphQLApi.ApiId}/*"
- DynamoDBCrudPolicy:
TableName: !Ref ChatMessagesTable
- DynamoDBCrudPolicy:
TableName: !Ref IdHelperChatMemoryTable
- DynamoDBReadPolicy:
TableName: !Ref ConfigurationTable
- S3CrudPolicy:
BucketName: !If
- ShouldCreateReportingBucket
- !Ref ReportingBucket
- !Ref ReportingBucketName
- Statement:
- Effect: Allow
Action:
- athena:StartQueryExecution
- athena:GetQueryExecution
- athena:GetQueryResults
- athena:StopQueryExecution
Resource:
- !Sub "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/primary"
- !Sub "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:datacatalog/*"
- Effect: Allow
Action:
- s3:ListBucket
- s3:GetBucketLocation
- s3:GetBucketVersioning
- s3:GetObject
- s3:PutObject
- s3:DeleteObject
- s3:AbortMultipartUpload
- s3:ListMultipartUploadParts
Resource: !Sub
- "${BucketArn}/*"
- BucketArn: !If
- ShouldCreateReportingBucket
- !GetAtt ReportingBucket.Arn
- !Sub "arn:${AWS::Partition}:s3:::${ReportingBucketName}"
- Effect: Allow
Action:
- glue:GetTable
- glue:GetTables
- glue:GetDatabase
- glue:GetDatabases
- glue:GetPartitions
Resource:
- !Sub "arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:catalog"
- !Sub "arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:database/${ReportingDatabase}"
- !Sub "arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:table/${ReportingDatabase}/*"
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource:
- !Sub "arn:${AWS::Partition}:bedrock:*::foundation-model/*"
- !Sub "arn:${AWS::Partition}:bedrock:${AWS::Region}:${AWS::AccountId}:inference-profile/*"
- Effect: Allow
Action:
- aws-marketplace:Subscribe
- aws-marketplace:Unsubscribe
- aws-marketplace:ViewSubscriptions
Resource: "*"
- !If
- HasGuardrailConfig
- Effect: Allow