Skip to content

Commit d89d2ba

Browse files
committed
Enhancing A2I template and adding logic for failed review tasks
1 parent d865586 commit d89d2ba

File tree

2 files changed

+7
-42
lines changed
  • patterns/pattern-1/src/hitl-process-function
  • src/lambda/get_stepfunction_execution_resolver

2 files changed

+7
-42
lines changed

patterns/pattern-1/src/hitl-process-function/index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,12 @@ def lambda_handler(event, context):
474474
)
475475
logger.info(f"Sent task failure for execution {execution_id}")
476476

477-
# Update document tracking to Failed
477+
# Update document tracking to FAILED
478478
tracking_table.update_item(
479479
Key={'PK': f"document#{document_id}", 'SK': 'metadata'},
480480
UpdateExpression="SET HITLStatus = :status, HITLCompletionTime = :time",
481481
ExpressionAttributeValues={
482-
':status': "Failed",
482+
':status': "FAILED",
483483
':time': datetime.datetime.now(datetime.timezone.utc).isoformat()
484484
}
485485
)
@@ -488,8 +488,8 @@ def lambda_handler(event, context):
488488
Key={'PK': f"doc#{document_id}", 'SK': 'none'},
489489
UpdateExpression="SET ObjectStatus = :status, HITLStatus = :hitlStatus",
490490
ExpressionAttributeValues={
491-
':status': "HITL_Failed",
492-
':hitlStatus': "Failed"
491+
':status': "HITL_FAILED",
492+
':hitlStatus': "FAILED"
493493
}
494494
)
495495
else:

src/lambda/get_stepfunction_execution_resolver/index.py

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,6 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
3030
# Log incoming request
3131
logger.info(f"Received request: {json.dumps(event)}")
3232

33-
# Safely extract execution ARN
34-
if 'arguments' not in event:
35-
logger.error("Missing 'arguments' in event")
36-
return {
37-
'executionArn': 'Unknown',
38-
'status': 'ERROR',
39-
'error': "Missing arguments in request",
40-
'steps': []
41-
}
42-
43-
if 'executionArn' not in event['arguments']:
44-
logger.error("Missing 'executionArn' in arguments")
45-
return {
46-
'executionArn': 'Unknown',
47-
'status': 'ERROR',
48-
'error': "Missing executionArn in arguments",
49-
'steps': []
50-
}
51-
5233
execution_arn = event['arguments']['executionArn']
5334
logger.info(f"Getting execution details for: {execution_arn}")
5435

@@ -61,12 +42,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
6142
except Exception as api_error:
6243
logger.error(f"describe_execution API call failed: {str(api_error)}")
6344
logger.error(f"Error details: {traceback.format_exc()}")
64-
return {
65-
'executionArn': execution_arn,
66-
'status': 'ERROR',
67-
'error': f"Failed to describe execution: {str(api_error)}",
68-
'steps': []
69-
}
45+
raise api_error
7046

7147
api_duration = (datetime.now() - start_time).total_seconds()
7248
logger.info(f"describe_execution API call took {api_duration:.2f} seconds")
@@ -107,12 +83,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
10783
except Exception as history_error:
10884
logger.error(f"Failed to fetch execution history page {page_count}: {str(history_error)}")
10985
logger.error(f"Error details: {traceback.format_exc()}")
110-
return {
111-
'executionArn': execution_arn,
112-
'status': 'ERROR',
113-
'error': f"Failed to fetch execution history: {str(history_error)}",
114-
'steps': []
115-
}
86+
raise history_error
11687

11788
history_duration = (datetime.now() - history_start_time).total_seconds()
11889
logger.info(f"Retrieved {len(all_events)} total events in {page_count} pages, took {history_duration:.2f} seconds")
@@ -188,14 +159,8 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
188159
logger.error(f"Error getting Step Functions execution: {str(e)}")
189160
logger.error(f"Traceback: {traceback.format_exc()}")
190161
# Return error in a format that can be displayed in the UI
191-
execution_arn = 'Unknown'
192-
try:
193-
execution_arn = event.get('arguments', {}).get('executionArn', 'Unknown')
194-
except:
195-
pass
196-
197162
return {
198-
'executionArn': execution_arn,
163+
'executionArn': event['arguments'].get('executionArn', 'Unknown'),
199164
'status': 'ERROR',
200165
'error': f"Failed to retrieve execution details: {str(e)}",
201166
'steps': []

0 commit comments

Comments
 (0)