-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagentcore_lambda.py
More file actions
66 lines (59 loc) · 2.27 KB
/
Copy pathagentcore_lambda.py
File metadata and controls
66 lines (59 loc) · 2.27 KB
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
import json
import logging
import os
from typing import Any
log = logging.getLogger(__name__)
def lambda_handler(event: dict[str, Any], context: Any) -> dict[str, Any]:
"""
AWS Lambda entry point for Bedrock AgentCore deployment.
This wrapper allows AWS Bedrock to invoke the GridGuard Strands Agent
as an Action Group or as a direct Lambda integration.
"""
log.info("Received AgentCore event", extra={"event": event})
# Extract standard Bedrock Agent action group routing fields
action_group = event.get("actionGroup", "GridGuardStrandsActionGroup")
api_path = event.get("apiPath", "/smoke-test")
http_method = event.get("httpMethod", "POST")
try:
# Initialize the Strands Agent for a smoke test validation
# In this slim smoke-test artifact, we return a deterministic mock response
# to avoid packaging massive ML libraries like xgboost and pandas.
response_body = {
"status": "SUCCESS",
"message": "GridGuard Strands Agent successfully initialized in Bedrock AgentCore.",
"provider": os.environ.get("STRANDS_PROVIDER", "bedrock"),
"mock_mode": os.environ.get("MOCK_MODE", "true").lower() == "true",
}
return {
"messageVersion": "1.0",
"response": {
"actionGroup": action_group,
"apiPath": api_path,
"httpMethod": http_method,
"httpStatusCode": 200,
"responseBody": {
"application/json": {
"body": json.dumps(response_body)
}
}
}
}
except Exception as exc:
log.error("AgentCore smoke test failed", exc_info=True)
return {
"messageVersion": "1.0",
"response": {
"actionGroup": action_group,
"apiPath": api_path,
"httpMethod": http_method,
"httpStatusCode": 500,
"responseBody": {
"application/json": {
"body": json.dumps({
"status": "ERROR",
"message": str(exc)
})
}
}
}
}