We just released Swift OpenAPI Lambda transport 2.1.0, with support for exposing your functions behind an Application Load Balancer (ALB), in addition to the existing support for API Gateway HTTP API.
In your code, just conform to the OpenAPILambdaALB (instead of the OpenAPILambdaHttpAPI that you use for the API Gateway).
Look at the new example in Examples/quoteapi-alb directory.
@main
struct QuoteServiceALBImpl: APIProtocol, OpenAPILambdaALB {
func register(transport: OpenAPILambdaTransport) throws {
try self.registerHandlers(on: transport)
}
static func main() async throws {
let openAPIService = QuoteServiceALBImpl()
try await openAPIService.run()
}
// the functions generated by the OpenAPI plugin
func getQuote(_ input: Operations.getQuote.Input) async throws -> Operations.getQuote.Output {
...
}
}
As usual, continue to share your feedback and open issues. The full change log is below.
ALB or API Gateway?
- ALB integrates Lambda functions as a backend target, supporting low-latency and flexible routing, and basic authentication.
- API Gateway HTTP API is a managed gateway for REST, HTTP, and WebSocket APIs, offering rich features such as request validation, usage plans, custom authorizers, and integration with AWS managed services (e.g., Cognito).
My mental model to choose which one to use
- ALB fits when integrating Lambdas into broader web applications, distributing HTTP traffic or exposing serverless functions alongside container services or EC2.
- API Gateway is best for building APIs, complex microservices, or needs requiring request validation, throttling, and security integrations (OAuth, API Key, CSP).
- Cost: ALB is generally cheaper at scale and for high RPS traffic, while API Gateway may be more economical for low-volume APIs due to its rich feature set.
- API Gateway allows multiple API versions and SDK auto-generation, aiding mobile and client app backward compatibility.
- Latency: API Gateway introduces more overhead compared to ALB, but offers more features like transformation, validation, and direct AWS integrations.