mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-06-02 07:27:33 +00:00
Add Hummingbird web framework integration example for AWS Lambda **Motivation:** Developers using the Hummingbird web framework need a clear example of how to integrate it with AWS Lambda. The existing examples focus on basic Lambda handlers, but don't demonstrate how to use popular Swift web frameworks like Hummingbird in a serverless context. **Modifications:** Added a complete Hummingbird Lambda example in Examples/Hummingbird/ including Package.swift with Hummingbird Lambda dependencies, main.swift demonstrating router setup with API Gateway V2 integration, SAM template for deployment, and comprehensive README documentation with build, deploy, and usage instructions. **Result:** Developers can now easily create AWS Lambda functions using the Hummingbird web framework, with a working example that shows router configuration, API Gateway integration, and complete deployment workflow using familiar Hummingbird syntax.
60 lines
2.0 KiB
Swift
60 lines
2.0 KiB
Swift
// swift-tools-version: 6.1
|
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
|
|
|
import PackageDescription
|
|
|
|
// needed for CI to test the local version of the library
|
|
import struct Foundation.URL
|
|
|
|
let package = Package(
|
|
name: "HBLambda",
|
|
platforms: [.macOS(.v15)],
|
|
dependencies: [
|
|
.package(
|
|
url: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
|
|
from: "2.0.0-beta.1"
|
|
),
|
|
.package(
|
|
url: "https://github.com/hummingbird-project/hummingbird-lambda.git",
|
|
branch: "main"
|
|
),
|
|
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.1.0"),
|
|
],
|
|
targets: [
|
|
.executableTarget(
|
|
name: "HBLambda",
|
|
dependencies: [
|
|
.product(name: "HummingbirdLambda", package: "hummingbird-lambda"),
|
|
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
|
|
]
|
|
)
|
|
]
|
|
)
|
|
|
|
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
|
|
localDepsPath != "",
|
|
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
|
|
v.isDirectory == true
|
|
{
|
|
// when we use the local runtime as deps, let's remove the dependency added above
|
|
let indexToRemove = package.dependencies.firstIndex { dependency in
|
|
if case .sourceControl(
|
|
name: _,
|
|
location: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
|
|
requirement: _
|
|
) = dependency.kind {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
if let indexToRemove {
|
|
package.dependencies.remove(at: indexToRemove)
|
|
}
|
|
|
|
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
|
|
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
|
|
package.dependencies += [
|
|
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
|
|
]
|
|
}
|