from cxone_sdk import data_action
import time
import logging
logger = logging.getLogger('cxone.handler')
def handler(event, context):
retries = 3
for attempt in range(retries):
try:
result = call_external_service(event['params'])
return {"status": "success", "data": result}
except Exception as e:
if attempt < retries - 1:
time.sleep(2 ** attempt)
continue
logger.error(f"Final failure: {e}", exc_info=True)
raise data_action.ActionError(code="SERVICE_TIMEOUT", message=str(e))
{
"name": "ValidateCustomerData",
"type": "invokePython",
"configuration": {
"errorCodes": [
{"code": "VALIDATION_FAILED", "message": "Input does not match schema"},
{"code": "SERVICE_TIMEOUT", "message": "Upstream API did not respond"}
]
}
}
The handler script utilizes cxone_sdk to intercept exceptions and map them to the defined ERRORCODES. The external invocation is encapsulated within a RETRY_LOOP utilizing exponential backoff. Transient 503 exceptions should initiate the retry sequence; however, the ARCHITECT_FLOW diverts immediately to the FALLBACK_PATH. The exc_info=True parameter fails to propagate diagnostic data to the CXone logging infrastructure.
Concurrently, the deployment attempts to expose failure metrics via a /metrics endpoint on the associated Lambda instance. The SDK does not natively track RETRY_ATTEMPTS. The health report generator retrieves only the final execution timestamp and disregards the error mapping configuration entirely. The RETRY_LOOP executes correctly in local environments. Upon deployment via the Studio snippet, the error codes are suppressed. IAM_ROLES and VPC_ENDPOINTS have been verified. No anomalies are present in the console. The monitoring endpoint returns a 404 when queried from the flow. The environment operates on python 3.9 with cxone_sdk v2.4.1 within the London region. Guidance is required to compel the SDK to emit the STRUCTURED_ERROR_RESPONSE. Execution traces terminate at the RETRY_BOUNDARY.