Deploy one voice AI agent file as an AWS Lambda handler for both call-flow and tool requests behind basic authentication.
serverless
The claim
AgentBase.run() picks its mode from the environment. AWS_LAMBDA_FUNCTION_NAME means Lambda, FUNCTION_TARGET or K_SERVICE mean Google Cloud Functions, and FUNCTIONS_WORKER_RUNTIME means Azure Functions. GATEWAY_INTERFACE means CGI, and nothing means a local server. In Lambda mode it reads an API Gateway event and returns {"statusCode", "headers", "body"}. The mode detection is get_execution_mode() in core/logging_config.py; the Lambda branch is handle_serverless_request in core/mixins/serverless_mixin.py.
Why it holds
Basic auth does not go away. _check_lambda_auth in core/mixins/auth_mixin.py reads the event’s Authorization header and compares it with the credentials the SDK took from SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD.
How it works
agent = StockAgent()
def handler(event, context):
return agent.run(event, context)
if __name__ == "__main__":
agent.run(host="0.0.0.0", port=3000) # a local server when nothing else is set
What the function returns for a GET / with valid credentials:
For a POST /swaig whose body is the platform’s tool payload, body is the handler’s result: {"response": "14 of SK-2210 in stock."}. The Lambda branch reads rawPath (HTTP API payload v2) or pathParameters.proxy (REST API v1). When the event sets isBase64Encoded, the SDK decodes the body. It takes the function name and arguments from the POST body the way the HTTP routes do.
Limitations
The verifier proves the Lambda branch on this machine, not a deployment. Cold starts, timeouts and API Gateway’s own configuration are yours to size.
The SDK renders tool webhooks and post_prompt_url from the host it computes in get_full_url (agent_base.py), which honours SWML_PROXY_URL_BASE. A deployment without it has no working tools; the verifier sets it and checks the rendered URL.
What to change first
Delete AWS_LAMBDA_FUNCTION_NAME from the verifier’s environment and run it. run() no longer detects Lambda and tries to start a server, so the first assertion never gets a dict back. The mode is the environment, and only the environment.