handle_serverless_request
handle_serverless_request
Handle incoming requests in serverless environments. This method dispatches to the appropriate handler based on the detected (or forced) execution mode: CGI, Lambda, Google Cloud Functions, or Azure Functions.
In most cases, use run() instead,
which auto-detects the environment and calls this method when appropriate. Call
handle_serverless_request() directly only when you need explicit control over the
serverless dispatch.
The method automatically:
- Parses the request body for SWAIG function calls
- Routes to the correct SWAIG function handler
- Returns the SWML document for root path requests
- Validates authentication credentials
Supported platforms: AWS Lambda (HTTP API v1 and v2), Google Cloud Functions (Flask), Azure Functions (HttpRequest/HttpResponse), and CGI.
Parameters
event
Platform-specific event or request object:
- Lambda: The event dictionary from the Lambda handler
- Google Cloud Functions: The Flask
requestobject - Azure Functions: The
HttpRequestobject - CGI: Not used (reads from
stdinand environment variables)
context
Platform-specific context object (Lambda context, etc.).
mode
Override the auto-detected execution mode.
"cgi"— CGI gateway interface"lambda"— AWS Lambda"google_cloud_function"— Google Cloud Functions"azure_function"— Azure Functions
Returns
Platform-specific response:
- Lambda:
dictwithstatusCode,headers, andbody - Google Cloud Functions: Flask
Responseobject - Azure Functions:
HttpResponseobject - CGI: Response string printed to stdout