16 Commits
Author SHA1 Message Date
Sébastien Stormacq 97b2e6d017 Add support for Lambda functions exposed behind an Application Load Balancer (ALB) (#29)
This PR adds support for exposing Swift OpenAPI Lambda functions behind
an Application Load Balancer (ALB), providing an alternative to API
Gateway for HTTP routing to Lambda functions.

## Changes

### New ALB Support
- **OpenAPILambdaALB Protocol**: New protocol for ALB integration
alongside existing API Gateway support
- **ALB Event Handling**: Added `ALBTargetGroupRequest` and
`ALBTargetGroupResponse` support
- **HTTP Request Conversion**: Extension methods to convert ALB events
to/from HTTP requests/responses

### Core Library Updates
- **ALB-related source files**: New `/Sources/ALB/` directory with
ALB-specific implementations
- **Event Type Support**: Support for `ALBTargetGroupRequest` events
from Elastic Load Balancing
- **Response Mapping**: Proper mapping from OpenAPI responses to ALB
target group responses

### Complete ALB Example
- **QuoteAPI ALB Example**: Full working example in
`Examples/quoteapi-alb/`
- **Infrastructure as Code**: Complete SAM template with VPC, subnets,
security groups, and ALB
- **Build System**: Makefile and Docker build support for ALB deployment
- **Documentation**: Comprehensive README with ALB-specific deployment
instructions

### Key Files Added
```
Sources/ALB/
├── OpenAPILambdaALB.swift
└── ALBTargetGroup+HTTPRequest.swift

Examples/quoteapi-alb/
├── Package.swift
├── template.yaml
├── Makefile
├── README.md
├── Sources/QuoteAPI/QuoteService.swift
├── Sources/QuoteAPI/openapi.yaml
├── Sources/QuoteAPI/openapi-generator-config.yaml
└── events/GetQuote.json
```

## Usage

### Simple ALB Integration
```swift
@main
struct QuoteServiceALBImpl: APIProtocol, OpenAPILambdaALB {
    func register(transport: OpenAPILambdaTransport) throws {
        try self.registerHandlers(on: transport)
    }
    
    static func main() async throws {
        let service = QuoteServiceALBImpl()
        try await service.run()
    }
    
    // Your OpenAPI implementation...
}
```

### Key Differences from API Gateway
- Uses `OpenAPILambdaALB` instead of `OpenAPILambdaHttpApi`
- Handles `ALBTargetGroupRequest` events instead of
`APIGatewayV2Request`
- Returns `ALBTargetGroupResponse` instead of `APIGatewayV2Response`
- Requires VPC infrastructure (included in SAM template)
- No built-in authorization (implement via custom middleware if needed)

## Benefits

- **Cost Optimization**: ALB can be more cost-effective for high-traffic
applications
- **VPC Integration**: Native VPC support for private network access
- **Load Balancing**: Advanced load balancing features and health checks
- **WebSocket Support**: Future WebSocket support through ALB
- **Flexibility**: Choice between API Gateway and ALB based on use case

## Testing

- ✅ ALB example builds successfully with `sam build`
- ✅ Local testing with `sam local invoke`
- ✅ Complete infrastructure deployment via SAM
- ✅ HTTP requests properly routed through ALB to Lambda
- ✅ OpenAPI specification compatibility maintained

## Deployment

Deploy the ALB example:
```bash
cd Examples/quoteapi-alb
sam build && sam deploy --guided
```

Test the deployed endpoint:
```bash
curl http://[alb-dns-name]/stocks/AAPL
```

## Backward Compatibility

This is a purely additive change:
- Existing API Gateway implementations continue to work unchanged
- No breaking changes to existing APIs
- New ALB support is opt-in via protocol conformance
2025-10-26 09:10:09 +01:00
Sébastien Stormacq dec6bbdc3d Change links to /swift-server to /awslabs (#26)
Change links in `Package.swift`, README, and docs
2025-10-17 17:11:43 +02:00
Sébastien Stormacq c72834d93c Update to support AWS Lambda Runtime for Swift v2 (#22)
- Update this library to support the upcoming release of AWS Lambda
Runtime for Swift v2.
This change affects the public API (some `Sendable` added) and requires
a major version bump. I propose to release v2 to align this library's
major with the Swift AWS Lambda Runtime's major.

- Add a QuoteAPI example in the `Examples` directory
2025-09-06 11:34:56 +02:00
Victor Hugo Barros 78dcf0c864 Upgrade swift-aws-lambda-events (#19)
Upgrade swift-aws-lambda-events from version `0.x.x` to version `1.x.x`
2025-06-13 18:24:48 +02:00
Sébastien Stormacq d38a1f6b28 reduce platforms dependencies 2024-10-16 08:24:38 +02:00
Sébastien Stormacq 8df4cc5ce8 swift-format 2024-10-16 08:16:34 +02:00
Sébastien Stormacq c69b925a23 simplify dependencies 2024-10-16 08:11:11 +02:00
Sébastien Stormacq ccf4ef01fe migrate to swift-test (#9)
* migrate to swift-test

* differentiate Swift 6.x from Swift 5.x

* swift-format
2024-10-15 21:22:27 +02:00
Sebastien Stormacq 05d897fef4 add StrictConcurrency=complete to prepare for Swift 6 2024-05-24 12:06:13 +02:00
Sebastien Stormacq a1caf89756 Update swift lambda event dependency to version 0.3.0 2024-05-23 11:01:48 +02:00
Sebastien Stormacq e5c37fc874 use from instead of branch for swift docc plugin 2023-12-14 08:58:42 -05:00
Sebastien Stormacq 8ef6abfa74 use from instead of branch for lambda events 2023-12-14 08:53:09 -05:00
Sebastien Stormacq 348a8026b8 use from instead of branch for AWS Lambda Runtime dependency 2023-12-14 08:45:19 -05:00
Sebastien Stormacq b3c55169eb do not use .upToNextMinor in dependencies definitions 2023-12-14 07:23:43 -05:00
Sebastien Stormacq a533a49bbd bump up iOS version to allow to compile with Xcode 2023-12-12 22:44:20 -05:00
Sebastien Stormacq 4c84d010a2 initial commit 2023-12-12 21:51:48 -05:00