@@ -87,7 +87,6 @@ module "documentai" {
8787 source = " ../../modules/document-data-extraction/resources"
8888
8989 standard_output_configuration = local. document_data_extraction_config . standard_output_configuration
90- override_configuration = local. document_data_extraction_config . override_configuration
9190 tags = local. tags
9291
9392 blueprints = concat (
@@ -350,6 +349,44 @@ resource "aws_dynamodb_table" "document_batches" {
350349 tags = local. tags
351350}
352351
352+ # -------------------
353+ # Bedrock Classification Config (SSM)
354+ # -------------------
355+ resource "aws_ssm_parameter" "bedrock_classification_model_id" {
356+ count = local. document_data_extraction_config != null ? 1 : 0
357+
358+ name = " /service/${ local . service_name } /bedrock/classification-model-id"
359+ type = " String"
360+ value = " anthropic.claude-3-haiku-20240307-v1:0"
361+
362+ lifecycle {
363+ ignore_changes = [value ]
364+ }
365+ }
366+
367+ # <<DOCUMENT_TYPES>> in the classification prompt needs to be dynamically
368+ # replaced with the document types that BDA is configured to extract. Store prompt
369+ # in SSM Parameter Store; application reads and update it at runtime.
370+ resource "aws_ssm_parameter" "bedrock_classification_prompt" {
371+ count = local. document_data_extraction_config != null ? 1 : 0
372+
373+ name = " /service/${ local . service_name } /bedrock/classification-prompt"
374+ type = " String"
375+ value = <<- EOT
376+ Analyze this image. Respond in JSON only:
377+ {"document_type": "string", "confidence": float 0-1, "document_count": int}
378+ ONLY use one of these exact values for document_type: <<DOCUMENT_TYPES>>
379+ Do not create new categories. If unsure, use 'other_document'.
380+ If it's not a document, use 'not_a_document'.
381+ document_count: how many separate documents are visible in this image?
382+ EOT
383+
384+ lifecycle {
385+ ignore_changes = [value ]
386+ }
387+ }
388+
389+
353390# -------------------
354391# IAM Policies
355392# -------------------
@@ -385,7 +422,7 @@ resource "aws_iam_policy" "dynamodb_read_write" {
385422 })
386423}
387424
388- resource "aws_iam_policy" "bedrock_invoke " {
425+ resource "aws_iam_policy" "bedrock_data_automation_invoke " {
389426 count = local. document_data_extraction_config != null ? 1 : 0
390427
391428 name = " ${ local . prefix } bedrock-invoke"
@@ -403,4 +440,29 @@ resource "aws_iam_policy" "bedrock_invoke" {
403440 Effect = " Allow"
404441 }]
405442 })
443+ }
444+
445+
446+ resource "aws_iam_policy" "bedrock_runtime_invoke" {
447+ count = local. document_data_extraction_config != null ? 1 : 0
448+
449+ name = " ${ local . prefix } bedrock-runtime-invoke"
450+ policy = jsonencode ({
451+ Version = " 2012-10-17"
452+ Statement = [
453+ {
454+ Action = " bedrock:InvokeModel"
455+ Resource = " arn:aws:bedrock:${ data . aws_region . current . name } ::foundation-model/*"
456+ Effect = " Allow"
457+ },
458+ {
459+ Action = " ssm:GetParameter"
460+ Resource = [
461+ aws_ssm_parameter.bedrock_classification_model_id[0 ].arn,
462+ aws_ssm_parameter.bedrock_classification_prompt[0 ].arn,
463+ ]
464+ Effect = " Allow"
465+ }
466+ ]
467+ })
406468}
0 commit comments