66 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
2.1.0
2025-10-26 09:10:09 +01:00
Sébastien Stormacq 946071d0b7 Change Build Badge (#32)
*Issue #, if available:*

*Description of changes:*


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2025-10-25 12:46:18 +02:00
Sébastien Stormacq 760814fbc4 Change Swift workflow to Ubuntu and simplify triggers (#31)
Updated the Swift workflow to run on Ubuntu instead of macOS and
simplified the trigger conditions.

*Issue #, if available:*

*Description of changes:*


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-10-25 12:38:15 +02:00
Sébastien Stormacq 62218f8e66 Update CI (#30)
Update CI to build on swift 6.0, swift 6.1 and swift 6.2 with recent
Ubuntu images (noble instead of jammy)
2025-10-25 12:18:13 +02:00
Sébastien Stormacq 4f2e953097 Adjust license files for /awslabs (#28)
Change the legal files and the license header in source files according
to AWS standards
2025-10-21 21:06:59 +02:00
Sébastien Stormacq 73e84943c3 Remove GH Action on push (#27)
only PR are authorized

*Issue #, if available:*

*Description of changes:*


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2025-10-17 17:21:45 +02: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 5063d3619c Fix a typo in the README (#25)
n/a
2025-10-17 08:21:44 +02:00
Sébastien Stormacq 10f3e99c4d Apply recommendation for security and reliability (#24)
Apply recommendations in code and documentation

- [CI] restrict permissions to `read-all` instead of the default
`write-all`
- Example `openapi.yaml` : add a note about using `security:` definition
when deploying to production
- Example `README.md` : add a note about Lambda functions configuration
with improved security and scalability changes for production
environment
2.0.0
2025-09-27 12:05:20 +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
2.0.0-beta.1
2025-09-06 11:34:56 +02:00
Sébastien Stormacq 6a54484782 Add quote api example (#20)
In preparation for a v2 release that will support the Lambda Runtime v2, I'm adding an end-to-end example project
0.3.0
2025-08-30 22:31:12 +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`
0.2.1
2025-06-13 18:24:48 +02:00
Franz Busch 1246e44308 Update release.yml (#17)
Update the release.yml file with the latest label changes
2024-12-18 14:59:05 +01:00
Sébastien Stormacq 97183bc4d5 fix badge (#15)
* fix badge

* Add semantic version label check

* disable yaml linter
2024-11-26 14:34:06 +01:00
Franz Busch e5573fd0de Merge pull request #13 from swift-server/FranzBusch-patch-1
Rename pull_request.yaml to pull_request.yml
2024-11-26 12:22:10 +01:00
Franz Busch 60725a37aa Rename pull_request.yaml to pull_request.yml 2024-11-26 12:19:11 +01:00
Emlyn Murphy eec0a058f7 Fix Query String Parameters Being Ignored (#11)
* Put query string into the path for OpenAPIGenerator code

* minor comments and formatting changes

---------

Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
0.2.0
2024-10-30 18:22:56 +01:00
Sébastien Stormacq a59a5721fc use SwiftLang's license header check (#10)
* use SwiftLang's license header check with https://github.com/swiftlang/github-workflows/pull/36

* remove .licenseignore fril from .licenseignore
2024-10-17 23:10:54 +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
Sébastien Stormacq f967634375 add build badge to readme 2024-10-15 19:31:19 +02:00
Sébastien Stormacq c29e1fd011 use swiftlang CI workflow
add license check

add readme build badge
2024-10-15 19:30:42 +02:00
Sébastien Stormacq 576602bcef add a github action 2024-10-15 16:40:48 +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 0.1.2 2024-05-23 11:01:48 +02:00
Sebastien Stormacq f596b2226a update soundness checks 2024-05-23 11:00:42 +02:00
Sebastien Stormacq 2b01689bcc add a sample HTTP API Gateway event JSON fiel for local testing 2024-05-15 13:17:14 +02:00
Sebastien Stormacq bef163556a update to GA version of Swift 5.10 2024-05-15 13:11:36 +02:00
Sebastien Stormacq 0a4c77d7c8 make swift-format happy 2024-05-15 12:57:52 +02:00
Sebastien Stormacq 0c14afac03 restore original license header in files borrowed from the Swift OpenAPI Generator project 2024-05-15 12:57:43 +02:00
Sebastien Stormacq 52b6fc9da5 remove github actions 2023-12-20 17:53:34 -05:00
Sebastien Stormacq 60f4bd2aae move the comments outside of the cat EOF blocks to avoid error with some shell + fix minor typos 2023-12-18 08:16:07 -05:00
Sebastien Stormacq 33cc99d440 explictly create an API route in the SAM template 2023-12-17 16:43:11 -05:00
Sébastien Stormacq 5e50eaee6d use x64 macOS for github action 2023-12-16 07:49:24 -05:00
Sébastien Stormacq fe7fa5dcc8 add build on linux 2023-12-15 17:08:49 -05:00
Sébastien Stormacq 9d0173a4e6 Update for macOS 13 Apple Silicon 2023-12-15 16:58:58 -05:00
Sébastien Stormacq 0203f3ff4c Update README.md with badges 2023-12-15 16:56:42 -05:00
Sébastien Stormacq f3a641543e force usae of xcode 15 2023-12-15 16:52:07 -05:00
Sébastien Stormacq cdf89cc630 Add CI workflow for github 2023-12-15 16:42:07 -05:00
Sebastien Stormacq 742da3d569 move from branch to from in the README file 2023-12-14 09:03:48 -05:00
Sebastien Stormacq e5c37fc874 use from instead of branch for swift docc plugin 0.1.1 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 22b6bbf566 update .gitignore 2023-12-14 08:44:50 -05:00
Sebastien Stormacq 8d4c3f3390 remove Package.resolved from the repo 2023-12-14 08:42:52 -05:00
Sebastien Stormacq 790e571e91 map Swift errors to HTTP return codes (https://github.com/sebsto/swift-openapi-lambda/issues/2) 0.1.0 2023-12-14 08:08:22 -05:00
Sebastien Stormacq f3b145dbfb document the API Gateway pass through to fix https://github.com/sebsto/swift-openapi-lambda/issues/4 2023-12-14 08:07:47 -05:00
Sebastien Stormacq b3c55169eb do not use .upToNextMinor in dependencies definitions 2023-12-14 07:23:43 -05:00