-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
834 lines (699 loc) · 23.3 KB
/
main.tf
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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.61.0"
}
}
}
provider "aws" {
region = "us-west-2" # Replace with your desired region
}
variable "bucket_name" {
type = string
description = "Name of the S3 bucket to create"
default = "my-llm-pdf-bucket-12344"
}
variable "project_name" {
description = "The name of the project"
type = string
default = "compliance-check"
}
variable "environment" {
description = "The deployment environment"
type = string
default = "prod"
}
data "archive_file" "lambda_zip" {
type = "zip"
source_dir = "${path.module}/function"
output_path = "${path.module}/function/lambda_function.zip"
}
# Archive file for Lambda Layer
data "archive_file" "layer_zip" {
type = "zip"
source_dir = "${path.module}/layer/"
output_path = "${path.module}/layer/layer.zip"
}
# Lambda Layer
resource "aws_lambda_layer_version" "libs" {
filename = "layer/layer.zip" # Ensure you zip your layer content
layer_name = "blank-python-lib"
compatible_runtimes = ["python3.8"]
description = "Dependencies for the blank-python sample app1"
}
resource "aws_lambda_function" "bedrock_lex_lambda" {
filename = data.archive_file.lambda_zip.output_path
function_name = "BedRockLexLambda"
role = aws_iam_role.bedrock_lambda_execution_role.arn
handler = "lambda_lex_function.lambda_handler"
runtime = "python3.8"
timeout = 500
memory_size = 256
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
environment {
variables = {
KENDRA_INDEX_ID = aws_kendra_index.kendra_index.id
KENDRA_INDEX_NAME = "${aws_kendra_index.kendra_index.name}-index"
}
}
layers = [aws_lambda_layer_version.libs.arn]
}
resource "aws_lambda_function" "bedrock_aws_config_lambda" {
filename = data.archive_file.lambda_zip.output_path
function_name = "BedRockAwsConfigLambda"
role = aws_iam_role.bedrock_lambda_execution_role.arn
handler = "lambda_aws_config_function.lambda_handler"
runtime = "python3.8"
timeout = 500
memory_size = 256
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
environment {
variables = {
KENDRA_INDEX_ID = aws_kendra_index.kendra_index.id
KENDRA_INDEX_NAME = "${aws_kendra_index.kendra_index.name}-index"
EMAIL_FROM = "[email protected]"
EMAIL_TO = "[email protected]"
EMAIL_SUBJECT = "AWS Config Compliance Change Notification"
}
}
layers = [aws_lambda_layer_version.libs.arn]
}
resource "aws_iam_role" "bedrock_lambda_execution_role" {
name = "BedRockLambdaExecutionRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
resource "aws_iam_role_policy" "lambda_ses_policy" {
name = "lambda_ses_policy"
role = aws_iam_role.bedrock_lambda_execution_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ses:SendEmail",
"ses:SendRawEmail"
]
Resource = "*"
}
]
})
}
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
role = aws_iam_role.bedrock_lambda_execution_role.name
}
resource "aws_iam_role_policy" "bedrock_access" {
name = "BedrockAccess"
role = aws_iam_role.bedrock_lambda_execution_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "bedrock:*"
Resource = "*"
}
]
})
}
# EventBridge rule
resource "aws_cloudwatch_event_rule" "compliance_check_rule" {
name = "${var.project_name}-${var.environment}-rule"
description = "Rule to trigger the Lambda function for compliance checks"
event_pattern = jsonencode({
source = ["aws.config"]
detail-type = ["Config Rules Compliance Change"]
detail = {
complianceType = ["COMPLIANT", "NON_COMPLIANT", "NOT_APPLICABLE", "INSUFFICIENT_DATA"]
}
})
tags = {
Name = "${var.project_name}-${var.environment}-rule"
Environment = var.environment
Project = var.project_name
ManagedBy = "Terraform"
}
}
# EventBridge target (Lambda function)
resource "aws_cloudwatch_event_target" "lambda_target" {
rule = aws_cloudwatch_event_rule.compliance_check_rule.name
target_id = "${var.project_name}-${var.environment}-lambda-target"
arn = aws_lambda_function.bedrock_aws_config_lambda.arn
input_transformer {
input_paths = {
detail = "$.detail"
detailType = "$.detail-type"
source = "$.source"
time = "$.time"
id = "$.id"
region = "$.region"
resources = "$.resources"
accountId = "$.account"
}
input_template = <<EOF
{
"action": "CheckCompliance",
"event": {
"id": <id>,
"detail-type": <detailType>,
"source": <source>,
"account": <accountId>,
"time": <time>,
"region": <region>,
"resources": <resources>,
"detail": <detail>
}
}
EOF
}
}
# IAM role for the Bedrock agent
resource "aws_iam_role" "bedrock_agent_role" {
name = "bedrock_agent_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "bedrock.amazonaws.com"
}
}
]
})
}
# AWS Bedrock agent
resource "aws_bedrockagent_agent" "config_non_compliant_agent" {
agent_name = "ConfigNonCompliantAgent"
description = "Agent to handle AWS Config non-compliant events"
# role_arn = aws_iam_role.bedrock_agent_role.arn
agent_resource_role_arn = aws_iam_role.bedrock_agent_role.arn
instruction = "Monitor AWS Config events for non-compliant resources and integrate with the existing Lambda function."
foundation_model = "anthropic.claude-v2"
}
# AWS Bedrock agent action group
resource "aws_bedrockagent_agent_action_group" "config_action_group" {
agent_id = aws_bedrockagent_agent.config_non_compliant_agent.id
agent_version = "DRAFT"
action_group_name = "ConfigComplianceActions"
description = "Actions for handling AWS Config compliance events"
action_group_executor {
lambda = aws_lambda_function.bedrock_aws_config_lambda.arn
}
function_schema {
member_functions {
functions {
name = "HandleNonCompliantResource"
description = "Process non-compliant resource and take appropriate action"
parameters {
map_block_key = "resourceId"
type = "string"
description = "The ID of the non-compliant resource"
required = true
}
parameters {
map_block_key = "complianceType"
type = "string"
description = "The type of non-compliance"
required = true
}
parameters {
map_block_key = "configRuleName"
type = "string"
description = "The name of the Config rule that was violated"
required = true
}
}
}
}
}
# Lambda permission to allow EventBridge to invoke the function
resource "aws_lambda_permission" "allow_eventbridge" {
statement_id = "AllowExecutionFromEventBridge"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.bedrock_aws_config_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.compliance_check_rule.arn
}
resource "aws_iam_role_policy" "kendra_access" {
name = "KendraAccess"
role = aws_iam_role.bedrock_lambda_execution_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "kendra:*"
Resource = "*"
}
]
})
}
resource "aws_iam_role_policy" "s3_access" {
name = "S3Access"
role = aws_iam_role.bedrock_lambda_execution_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
]
Resource = [
"arn:aws:s3:::*",
"arn:aws:s3:::*/*"
]
}
]
})
}
resource "aws_s3_bucket" "s3_bucket" {
bucket = var.bucket_name
}
# Create the AWS Bedrock Guardrail resource
resource "awscc_bedrock_guardrail" "pii_masking_guardrail" {
name = "PII-Masking-Guardrail"
blocked_input_messaging = "Blocked input"
blocked_outputs_messaging = "Blocked output"
description = "Guardrail to mask sensitive and PII information in AWS Bedrock"
sensitive_information_policy_config = {
# ["ADDRESS" "AGE" "AWS_ACCESS_KEY" "AWS_SECRET_KEY"
# │ "CA_HEALTH_NUMBER" "CA_SOCIAL_INSURANCE_NUMBER" "CREDIT_DEBIT_CARD_CVV" "CREDIT_DEBIT_CARD_EXPIRY" "CREDIT_DEBIT_CARD_NUMBER" "DRIVER_ID" "EMAIL"
# │ "INTERNATIONAL_BANK_ACCOUNT_NUMBER" "IP_ADDRESS" "LICENSE_PLATE" "MAC_ADDRESS" "NAME" "PASSWORD" "PHONE" "PIN" "SWIFT_CODE"
# │ "UK_NATIONAL_HEALTH_SERVICE_NUMBER" "UK_NATIONAL_INSURANCE_NUMBER" "UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER" "URL" "USERNAME" "US_BANK_ACCOUNT_NUMBER"
# │ "US_BANK_ROUTING_NUMBER" "US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER" "US_PASSPORT_NUMBER" "US_SOCIAL_SECURITY_NUMBER" "VEHICLE_IDENTIFICATION_NUMBER"],
pii_entities_config = [
{ action = "ANONYMIZE", type = "NAME" },
{ action = "BLOCK", type = "DRIVER_ID" },
{ action = "ANONYMIZE", type = "USERNAME" },
# { action = "ANONYMIZE", type = "EMAIL" },
{ action = "ANONYMIZE", type = "PHONE" },
{ action = "BLOCK", type = "US_SOCIAL_SECURITY_NUMBER" },
{ action = "ANONYMIZE", type = "CREDIT_DEBIT_CARD_NUMBER" },
{ action = "ANONYMIZE", type = "ADDRESS" },
{ action = "ANONYMIZE", type = "IP_ADDRESS" },
{ action = "ANONYMIZE", type = "AGE" },
{ action = "BLOCK", type = "AWS_ACCESS_KEY" },
{ action = "BLOCK", type = "AWS_SECRET_KEY" },
]
regexes_config = [
{
action = "BLOCK"
description = "Block SSN-like patterns"
name = "ssn_pattern"
pattern = "^\\d{3}-\\d{2}-\\d{4}$"
},
{
action = "ANONYMIZE"
description = "Mask custom employee ID format"
name = "employee_id_pattern"
pattern = "EMP-\\d{6}"
}
]
}
}
resource "aws_iam_role" "kendra_index_role" {
name = "KendraIndexRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "kendra.amazonaws.com"
}
}
]
})
}
resource "aws_iam_role_policy_attachment" "kendra_cloudwatch_logs" {
policy_arn = "arn:aws:iam::aws:policy/AWSOpsWorksCloudWatchLogs"
role = aws_iam_role.kendra_index_role.name
}
resource "aws_iam_role_policy" "kendra_index_policy" {
name = "KendraIndexPolicy"
role = aws_iam_role.kendra_index_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:GetObject",
"s3:ListBucket"
]
Resource = [
aws_s3_bucket.s3_bucket.arn,
"${aws_s3_bucket.s3_bucket.arn}/*"
]
}
]
})
}
resource "aws_kendra_index" "kendra_index" {
name = "YourStackName-index2"
role_arn = aws_iam_role.kendra_index_role.arn
edition = "DEVELOPER_EDITION"
}
resource "aws_kendra_data_source" "kendra_data_source" {
index_id = aws_kendra_index.kendra_index.id
name = "YourStackName-s3-datasource2"
type = "S3"
role_arn = aws_iam_role.kendra_data_source_role.arn
configuration {
s3_configuration {
bucket_name = aws_s3_bucket.s3_bucket.id
}
}
tags = {
Name = "YourStackName-s3-datasource2"
}
}
resource "aws_iam_role" "kendra_data_source_role" {
name = "KendraDataSourceRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "kendra.amazonaws.com"
}
}
]
})
}
resource "aws_iam_role_policy" "kendra_data_source_policy" {
name = "KendraDataSourcePolicy"
role = aws_iam_role.kendra_data_source_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:GetObject",
"s3:ListBucket"
]
Resource = [
aws_s3_bucket.s3_bucket.arn,
"${aws_s3_bucket.s3_bucket.arn}/*"
]
},
{
Effect = "Allow"
Action = [
"kendra:BatchPutDocument",
"kendra:BatchDeleteDocument"
]
Resource = aws_kendra_index.kendra_index.arn
}
]
})
}
resource "aws_cloudwatch_log_group" "lex_log_group" {
name = "/aws/lex/YourStackName2"
retention_in_days = 14
}
resource "aws_iam_role" "bot_runtime_role" {
name = "LexBotRuntimeRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lexv2.amazonaws.com"
}
}]
})
}
resource "aws_iam_role_policy" "lex_runtime_role_policy" {
name = "LexRuntimeRolePolicy"
role = aws_iam_role.bot_runtime_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"polly:SynthesizeSpeech",
"comprehend:DetectSentiment",
"lambda:InvokeFunction",
"s3:PutObject",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = "*"
},
{
Effect = "Allow"
Action = "s3:PutObject"
Resource = "${aws_s3_bucket.s3_bucket.arn}/lex-audio-logs/*"
},
{
Effect = "Allow"
Action = [
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = aws_cloudwatch_log_group.lex_log_group.arn
}
]
})
}
resource "aws_lambda_permission" "allow_lex" {
statement_id = "AllowExecutionFromLex"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.bedrock_lex_lambda.function_name
principal = "lexv2.amazonaws.com"
}
resource "aws_lexv2models_bot" "chatbot" {
name = "LLMChatbot"
role_arn = aws_iam_role.bot_runtime_role.arn
data_privacy {
child_directed = false
}
idle_session_ttl_in_seconds = 300
# type = "BOT"
}
# Add a null_resource to wait for the bot to be ready and not in versioning state
resource "null_resource" "wait_for_bot" {
depends_on = [aws_lexv2models_bot.chatbot]
provisioner "local-exec" {
command = <<EOF
echo "Starting bot status check..."
check_bot_status() {
aws lexv2-models describe-bot --bot-id ${aws_lexv2models_bot.chatbot.id} --region us-west-2 --query 'botStatus' --output text
}
bot_status=$(check_bot_status)
echo "Initial bot status: $bot_status"
while [ "$bot_status" != "Available" ]; do
echo "Waiting for bot to be Available... Current status: $bot_status"
sleep 10
bot_status=$(check_bot_status)
done
echo "Bot is Available. Checking for Versioning state..."
while [ "$bot_status" = "Versioning" ]; do
echo "Bot is in Versioning state. Waiting..."
sleep 10
bot_status=$(check_bot_status)
done
echo "Final bot status: $bot_status"
echo "Bot check complete. Proceeding with next steps."
EOF
}
}
resource "aws_lexv2models_bot_locale" "chatbot_locale" {
bot_id = aws_lexv2models_bot.chatbot.id
bot_version = "DRAFT"
locale_id = "en_US"
description = "LLM Bedrock Bot"
n_lu_intent_confidence_threshold = 0.70
voice_settings {
voice_id = "Ivy"
}
# Update default fallback to enable lambda hook
provisioner "local-exec" {
command = "aws lexv2-models update-intent --bot-id ${aws_lexv2models_bot.chatbot.id} --locale-id ${aws_lexv2models_bot_locale.chatbot_locale.locale_id} --bot-version DRAFT --intent-id FALLBCKINT --intent-name FallbackIntent --parent-intent-signature=AMAZON.FallbackIntent --dialog-code-hook enabled=true --region us-west-2"
}
}
resource "aws_lexv2models_bot_version" "chatbot_version" {
bot_id = aws_lexv2models_bot.chatbot.id
locale_specification = {
"en_US" = {
source_bot_version = "DRAFT"
}
}
}
resource "aws_lexv2models_intent" "chatbot" {
bot_id = aws_lexv2models_bot.chatbot.id
bot_version = aws_lexv2models_bot_locale.chatbot_locale.bot_version
locale_id = aws_lexv2models_bot_locale.chatbot_locale.locale_id
name = "HelloIntent"
dialog_code_hook {
enabled = true
}
sample_utterance {
utterance = "Hello"
}
}
# This builds the bot after creating an intent
resource "null_resource" "my_bot_build" {
depends_on = [aws_lexv2models_intent.chatbot]
triggers = {
bot_id = aws_lexv2models_bot.chatbot.id
locale_id = aws_lexv2models_bot_locale.chatbot_locale.locale_id
# intent = aws_lexv2models_intent.chatbot.sample_utterance
}
provisioner "local-exec" {
command = "./build_bot.sh ${aws_lexv2models_bot.chatbot.id} ${aws_lexv2models_bot_locale.chatbot_locale.locale_id}"
}
}
# Create a version after building
resource "aws_lexv2models_bot_version" "chatbot" {
depends_on = [null_resource.my_bot_build]
bot_id = aws_lexv2models_bot.chatbot.id
locale_specification = {
(aws_lexv2models_bot_locale.chatbot_locale.locale_id) = {
source_bot_version = aws_lexv2models_bot_locale.chatbot_locale.bot_version
}
}
}
# Create or update an alias after creating a new version
resource "null_resource" "my_bot_alias" {
depends_on = [aws_lexv2models_bot_version.chatbot]
triggers = {
bot_id = aws_lexv2models_bot.chatbot.id
locale_id = aws_lexv2models_bot_locale.chatbot_locale.locale_id
latest_version = aws_lexv2models_bot_version.chatbot.bot_version
lambda_arn = aws_lambda_function.bedrock_lex_lambda.arn
logs_arn = ""
}
provisioner "local-exec" {
command = "./upsert_bot_alias.sh ${aws_lexv2models_bot.chatbot.id} ${aws_lexv2models_bot_locale.chatbot_locale.locale_id} ${aws_lexv2models_bot_version.chatbot.bot_version} '${aws_lambda_function.bedrock_lex_lambda.arn}' ''"
}
}
# resource "null_resource" "update_fallback_intent" {
# depends_on = [aws_lexv2models_bot.chatbot]
# triggers = {
# always_run = "${timestamp()}"
# }
# provisioner "local-exec" {
# command = <<EOF
# echo "Starting bot status check..."
# check_bot_status() {
# aws lexv2-models describe-bot --bot-id ${aws_lexv2models_bot.chatbot.id} --region us-west-2 --query 'botStatus' --output text
# }
# bot_status=$(check_bot_status)
# echo "Initial bot status: $bot_status"
# while [ "$bot_status" != "Available" ]; do
# echo "Waiting for bot to be Available... Current status: $bot_status"
# sleep 10
# bot_status=$(check_bot_status)
# done
# echo "Bot is Available. Checking for Versioning state..."
# while [ "$bot_status" = "Versioning" ]; do
# echo "Bot is in Versioning state. Waiting..."
# sleep 10
# bot_status=$(check_bot_status)
# done
# echo "Final bot status: $bot_status"
# echo "Bot check complete. Proceeding with next steps."
# ALIAS_NAME="PublicAlias"
# # Check if the alias already exists
# CURRENT_ALIAS_ID=$(aws lexv2-models list-bot-aliases --bot-id ${aws_lexv2models_bot.chatbot.id} --query "botAliasSummaries[?botAliasName == '$ALIAS_NAME'].botAliasId | [0]" --output text)
# echo "Final alias id: $CURRENT_ALIAS_ID"
# if [[ $CURRENT_ALIAS_ID == "None" ]]; then
# echo "Creating a new alias"
# CURRENT_ALIAS_ID=$(aws lexv2-models create-bot-alias --bot-id ${aws_lexv2models_bot.chatbot.id} --bot-alias-name $ALIAS_NAME --bot-version 1 --output text)
# echo "Final bot status: $CURRENT_ALIAS_ID"
# fi
# echo "Updating the alias"
# # Enable lambda execution and chat logs
# aws lexv2-models update-bot-alias --bot-id ${aws_lexv2models_bot.chatbot.id} --bot-alias-id $CURRENT_ALIAS_ID --bot-alias-name $ALIAS_NAME --bot-version 1 --bot-alias-locale-settings '{"'$2'":{"enabled":true,"codeHookSpecification":{"lambdaCodeHook":{"lambdaARN":"'${bedrock_lex_lambda.lambda.arn}'","codeHookInterfaceVersion":"1.0"}}}}' --conversation-log-settings '{"textLogSettings":[{"enabled":true,"destination":{"cloudWatch":{"cloudWatchLogGroupArn":"'$5'","logPrefix":""}}}]}'
# echo "Fetching FallbackIntentId... ${aws_lexv2models_bot.chatbot.id}"
# FallbackIntentId=$(aws lexv2-models list-intents --bot-id ${aws_lexv2models_bot.chatbot.id} --bot-version DRAFT --locale-id en_US --query "intentSummaries[?intentName=='CustomFallbackIntent'].intentId" --output text)
# echo "Raw FallbackIntentId output: $FallbackIntentId"
# if [ -z "$FallbackIntentId" ]; then
# echo "FallbackIntentId is null. Exiting."
# exit 1
# else
# echo "Fetched FallbackIntentId: $FallbackIntentId"
# fi
# echo "Updating FallbackIntent with ID: $FallbackIntentId..."
# aws lexv2-models update-intent \
# --bot-id ${aws_lexv2models_bot.chatbot.id} \
# --bot-version DRAFT \
# --locale-id en_US \
# --intent-id $FallbackIntentId \
# --intent-name FallbackIntent \
# --fulfillment-code-hook '{"enabled": true}'
# echo "Update completed."
# EOF
# }
# }
# resource "awscc_bedrock_guardrail" "example" {
# name = "example_guardrail"
# blocked_input_messaging = "Sorry cannot answer this question"
# blocked_outputs_messaging = "Blocked output"
# description = "Example guardrail"
# content_policy_config = {
# filters_config = [
# {
# input_strength = "MEDIUM"
# output_strength = "MEDIUM"
# type = "HATE"
# },
# {
# input_strength = "HIGH"
# output_strength = "HIGH"
# type = "VIOLENCE"
# }
# ]
# }
# }
output "s3_bucket_name" {
description = "Name of the created S3 bucket"
value = aws_s3_bucket.s3_bucket.id
}
output "kendra_index_id" {
description = "ID of the created Kendra Index"
value = aws_kendra_index.kendra_index.id
}
output "kendra_data_source_id" {
description = "ID of the created Kendra Data Source"
value = aws_kendra_data_source.kendra_data_source.id
}
output "lex_bot_id" {
description = "The ID of the Lex bot"
value = aws_lexv2models_bot.chatbot.id
}
# Outputs
output "event_rule_arn" {
description = "ARN of the EventBridge rule"
value = aws_cloudwatch_event_rule.compliance_check_rule.arn
}
output "lambda_function_arn" {
description = "ARN of the target Lambda function"
value = aws_lambda_function.bedrock_aws_config_lambda.arn
}