lambda

package
v3.0.0-...-083f9db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package lambda adapts a net/http handler produced by the SignalWire Agents SDK (typically agent.AsRouter()) so it can run inside AWS Lambda.

The adapter translates a Lambda invocation event into a synthetic *http.Request, runs the underlying handler against an in-memory response recorder, and marshals the recorder's result back into the Lambda response type that matches the invoking event.

Two event shapes are supported, because they are the two ways an AI agent is realistically exposed over HTTP on Lambda:

  • Lambda Function URLs (events.LambdaFunctionURLRequest / LambdaFunctionURLResponse). This is the simplest deployment and the one we recommend; no API Gateway is required.

  • API Gateway HTTP API v2 (events.APIGatewayV2HTTPRequest / APIGatewayV2HTTPResponse). Identical payload shape in practice, but consumers with an API Gateway layer want the exact response type rather than an assignable alias.

The classic REST API (v1) payload is intentionally not supported as a first-class path to keep this package small. Users who need v1 can wrap it via github.com/awslabs/aws-lambda-go-api-proxy.

Usage

package main

import (
    "github.com/aws/aws-lambda-go/lambda"
    swlambda "github.com/signalwire/signalwire-go/v3/pkg/lambda"
    "github.com/signalwire/signalwire-go/v3/pkg/agent"
)

var a = agent.NewAgentBase(agent.WithName("MyAgent"), agent.WithRoute("/my-agent"))
var handler = swlambda.NewHandler(a.AsRouter())

func main() {
    lambda.Start(handler.HandleFunctionURL)
}

Because agent.AsRouter() installs routes relative to the agent's Route (e.g. /my-agent, /my-agent/swaig), the Lambda event's RawPath must line up with that Route. Lambda Function URLs preserve the full request path unchanged, so no rewriting is needed in the common case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler wraps an http.Handler so it can service AWS Lambda invocations. Construct one with NewHandler.

func NewHandler

func NewHandler(h http.Handler) *Handler

NewHandler returns a Handler that dispatches Lambda events to the given http.Handler. The handler is usually agent.AsRouter() but any http.Handler works.

Panics if h is nil to fail loudly at cold-start rather than silently returning 500 on every invocation.

func (*Handler) HandleAPIGatewayV2

HandleAPIGatewayV2 processes an API Gateway HTTP API v2 invocation. The payload shape is virtually identical to Function URLs, but the response type differs, so we provide a dedicated entry point.

func (*Handler) HandleFunctionURL

HandleFunctionURL processes a Lambda Function URL invocation. It is intended to be passed to github.com/aws/aws-lambda-go/lambda.Start.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL