Skip to content

Commit 1843e35

Browse files
dineshSajwandinsajwa
and
dinsajwa
authored
fix(bda): updated bda construct with schema file upload changes (#1061)
* fix(bda): updated bda construct with schema file upload changes --------- Co-authored-by: dinsajwa <[email protected]>
1 parent b9736ef commit 1843e35

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

lambda/aws-bedrock-data-automation/bda_blueprint/lambda.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from aws_lambda_powertools import Logger, Tracer, Metrics
1717
from aws_lambda_powertools.utilities.typing import LambdaContext
1818
from aws_lambda_powertools.utilities.data_classes import EventBridgeEvent, APIGatewayProxyEvent
19-
from manage_blueprint import create_blueprint,delete_blueprint,list_blueprints,get_blueprint,update_blueprint
19+
from manage_blueprint import create_blueprint,delete_blueprint,list_blueprints,get_blueprint,update_blueprint,DateTimeEncoder
2020
from create_schema import create_schema
2121

2222

@@ -98,11 +98,7 @@ def get_schema(bucket_name: str, schema_key: str) -> Dict[str, Any]:
9898
Key=schema_key
9999
)
100100
schema_content = json.loads(response['Body'].read().decode('utf-8'))
101-
logger.info("Successfully retrieved and parsed schema", extra={
102-
"schema_size": len(json.dumps(schema_content)),
103-
"bucket": bucket_name,
104-
"key": schema_key
105-
})
101+
logger.info(f"Successfully retrieved and parsed schema {schema_content}")
106102

107103
return schema_content
108104

@@ -180,12 +176,9 @@ def handler(event, context: LambdaContext):
180176
if not all(key in field for key in ['name', 'description', 'alias']):
181177
raise ValueError("Each field must contain 'name', 'description', and 'alias'")
182178

183-
# Create schema using the fields
179+
# Create schema using AWS BDA format
184180
try:
185-
DynamicSchema = create_schema(schema_fields)
186-
schema_instance = DynamicSchema()
187-
schema_content = json.dumps(schema_instance.model_json_schema())
188-
181+
schema_content = create_schema(schema_fields)
189182
except Exception as e:
190183
print("Error creating schema")
191184
return {
@@ -196,8 +189,6 @@ def handler(event, context: LambdaContext):
196189
})
197190
}
198191

199-
if not schema_content or not schema_content.strip():
200-
logger.warning("No Schema provided , creating a custom blueprint with no schema")
201192

202193
response= create_blueprint(schema_content,blueprint_details)
203194
response_msg='Blueprint created successfully'
@@ -214,7 +205,7 @@ def handler(event, context: LambdaContext):
214205
'body': json.dumps({
215206
'message': response_msg,
216207
'response': response
217-
})
208+
}, cls=DateTimeEncoder)
218209
}
219210

220211

@@ -226,6 +217,5 @@ def handler(event, context: LambdaContext):
226217
'body': json.dumps({
227218
'message': 'Unexpected error occurred',
228219
'error': str(e)
229-
})
220+
}, cls=DateTimeEncoder)
230221
}
231-

lambda/aws-bedrock-data-automation/bda_blueprint/manage_blueprint.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ def create_blueprint(schema_content,blueprint_details):
6565
client_token = blueprint_details.get('client_token', '')
6666
tags = blueprint_details.get('tags', [])
6767

68+
logger.info(" collecting request params...")
6869
# Prepare request parameters
6970
request_params = {
7071
'blueprintName': blueprint_name,
7172
'type': blueprint_type,
7273
'blueprintStage': blueprint_stage,
73-
'schema': schema_content,
7474
}
7575

76+
# Add schema if provided and not empty
77+
#schema_json = json.loads(schema_content)
78+
request_params['schema'] = json.dumps(schema_content) if isinstance(schema_content, dict) else schema_content
79+
80+
logger.info("Added schema_json...")
7681
# Add client token if provided
7782
if client_token:
7883
request_params['clientToken'] = client_token
@@ -81,11 +86,6 @@ def create_blueprint(schema_content,blueprint_details):
8186
if tags:
8287
request_params['tags'] = tags
8388

84-
logger.info("Creating blueprint", extra={
85-
"blueprint_name": blueprint_name,
86-
"blueprint_type": blueprint_type,
87-
"blueprint_stage": blueprint_stage,
88-
})
8989

9090
# Add encryption configuration if provided
9191
encryption_config = blueprint_details.get('encryption_config')
@@ -108,7 +108,9 @@ def create_blueprint(schema_content,blueprint_details):
108108
valid_encryption_config['kmsEncryptionContext'] = encryption_config['kmsEncryptionContext']
109109

110110
request_params['encryptionConfiguration'] = valid_encryption_config
111-
111+
112+
logger.info(f"Creating blueprint with request params: {request_params}" )
113+
112114
# Create blueprint
113115
response = bda_client.create_blueprint(**request_params)
114116
blueprint_arn = response["blueprint"]["blueprintArn"]
@@ -477,4 +479,3 @@ def delete_blueprint(blueprint_arn: str, blueprint_version: str = None) -> Dict[
477479
'error': str(e)
478480
})
479481
raise e
480-

lambda/aws-bedrock-data-automation/bda_project/lambda.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def process_api_gateway_event(event: Dict[str, Any]) -> Dict[str, Any]:
4545
api_event = APIGatewayProxyEvent(event)
4646
logger.info("Received API Gateway event", extra={
4747
"http_method": api_event.http_method,
48-
"path": api_event.path
48+
"path": api_event.path,
49+
"body": api_event.body
4950
})
5051

5152
if not api_event.body:
@@ -65,6 +66,8 @@ def handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any]:
6566
"""
6667
try:
6768
# Determine event source and process accordingly
69+
logger.info(f"Received event: {json.dumps(event)}")
70+
6871
if event.get("source") and event.get("detail-type"):
6972
project_config = process_event_bridge_event(event)
7073
else:

0 commit comments

Comments
 (0)