Skip to content

Commit f65de85

Browse files
Refactor BDA blueprint configuration and remove unused permissions
- Consolidate blueprints_path and aws_managed_blueprints into single blueprints list - Support mixed list of file paths and ARNs in blueprints variable - Add glob pattern expansion in service layer for blueprint files - Remove InvokeModel and InvokeModelWithResponseStream permissions (not needed for BDA)
1 parent ea72d79 commit f65de85

File tree

5 files changed

+40
-29
lines changed

5 files changed

+40
-29
lines changed

infra/app-flask/app-config/env-config/document_data_extraction.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ locals {
33
name = "${var.app_name}-${var.environment}"
44
input_bucket_name = "${var.app_name}-${var.environment}-bda-input"
55
output_bucket_name = "${var.app_name}-${var.environment}-bda-output"
6-
blueprints_path = "./document-data-extraction-blueprints/"
7-
aws_managed_blueprints = null
6+
7+
# List of blueprint file paths or ARNs
8+
# File paths are relative to the service directory
9+
# ARNs reference AWS-managed or existing custom blueprints
10+
blueprints = [
11+
"./document-data-extraction-blueprints/*"
12+
]
813

914
# BDA can only be deployed to us-east-1, us-west-2, and us-gov-west-1
1015
bda_region = "us-east-1"

infra/app-flask/service/document_data_extraction.tf

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
locals {
33
document_data_extraction_config = local.environment_config.document_data_extraction_config
44

5+
expanded_blueprints = local.document_data_extraction_config != null ? flatten([
6+
for bp in local.document_data_extraction_config.blueprints :
7+
# if it's a glob pattern (contains *), expand it
8+
can(regex("\\*", bp)) ? [
9+
for file in fileset(path.module, bp) : "${path.module}/${file}"
10+
] : [bp] # Otherwise use as-is (for ARNs or explicit paths)
11+
]) : []
12+
513
document_data_extraction_environment_variables = local.document_data_extraction_config != null ? {
614
DDE_INPUT_LOCATION = "s3://${local.prefix}${local.document_data_extraction_config.input_bucket_name}"
715
DDE_OUTPUT_LOCATION = "s3://${local.prefix}${local.document_data_extraction_config.output_bucket_name}"
@@ -55,19 +63,8 @@ module "dde" {
5563

5664

5765
standard_output_configuration = local.document_data_extraction_config.standard_output_configuration
58-
aws_managed_blueprints = local.document_data_extraction_config.aws_managed_blueprints
66+
blueprints = local.expanded_blueprints
5967
tags = local.tags
6068

61-
blueprints_map = {
62-
# JPG/PNG can be processed as DOCUMENT or IMAGE types, but IMAGE types can only
63-
# have a single custom blueprint so generally the blueprints will be for the DOCUMENT type
64-
for blueprint in fileset(local.document_data_extraction_config.blueprints_path, "*") :
65-
split(".", blueprint)[0] => {
66-
schema = file("${local.document_data_extraction_config.blueprints_path}/${blueprint}")
67-
type = "DOCUMENT"
68-
tags = local.tags
69-
}
70-
}
71-
7269
name = "${local.prefix}${local.document_data_extraction_config.name}"
7370
}

infra/modules/document-data-extraction/resources/access_control.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ resource "aws_iam_policy" "bedrock_access" {
66
data "aws_iam_policy_document" "bedrock_access" {
77
statement {
88
actions = [
9-
"bedrock:InvokeModel",
10-
"bedrock:InvokeModelWithResponseStream",
119
"bedrock:InvokeDataAutomationAsync",
1210
"bedrock:GetDataAutomationProject",
1311
"bedrock:GetBlueprint",

infra/modules/document-data-extraction/resources/main.tf

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,35 @@ locals {
77
}
88
]
99

10+
blueprint_arns = [
11+
for bp in var.blueprints : bp
12+
if startswith(bp, "arn:")
13+
]
14+
15+
blueprint_files = [
16+
for bp in var.blueprints : bp
17+
if !startswith(bp, "arn:")
18+
]
19+
20+
# create map of custom blueprints from files
21+
custom_blueprints_map = {
22+
for file_path in local.blueprint_files :
23+
replace(basename(file_path), ".json", "") => {
24+
schema = file(file_path)
25+
type = "DOCUMENT"
26+
tags = var.tags
27+
}
28+
}
29+
1030
all_blueprints = concat(
1131
# custom blueprints created from json schemas
1232
[for k, v in awscc_bedrock_blueprint.bda_blueprint : {
1333
blueprint_arn = v.blueprint_arn
1434
blueprint_stage = v.blueprint_stage
1535
}],
1636
# aws managed blueprints referenced by arn
17-
var.aws_managed_blueprints != null ? [
18-
for arn in var.aws_managed_blueprints : {
37+
length(local.blueprint_arns) > 0 ? [
38+
for arn in local.blueprint_arns : {
1939
blueprint_arn = arn
2040
blueprint_stage = "LIVE"
2141
}
@@ -35,7 +55,7 @@ resource "awscc_bedrock_data_automation_project" "bda_project" {
3555
}
3656

3757
resource "awscc_bedrock_blueprint" "bda_blueprint" {
38-
for_each = var.blueprints_map
58+
for_each = local.custom_blueprints_map
3959

4060
blueprint_name = "${var.name}-${each.key}"
4161
schema = each.value.schema

infra/modules/document-data-extraction/resources/variables.tf

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ variable "name" {
33
type = string
44
}
55

6-
variable "aws_managed_blueprints" {
6+
variable "blueprints" {
77
description = "List of AWS managed blueprint ARNs (stage defaults to LIVE)"
88
type = list(string)
99
default = null
@@ -117,12 +117,3 @@ variable "tags" {
117117
default = {}
118118

119119
}
120-
121-
variable "blueprints_map" {
122-
description = "the map of unique blueprints with keys as blueprint identifiers and values as blueprint objects"
123-
type = map(object({
124-
schema = string
125-
type = string
126-
tags = map(string)
127-
}))
128-
}

0 commit comments

Comments
 (0)