vapor-aws-lambda-runtime
Run your Vapor app on AWS Lambda. This package bridges the communication between swift-aws-lambda-runtime
and the Vapor framework. APIGateway requests are transformed into Vapor.Request
s and Vapor.Response
s are written back to the APIGateway. It intents to bring the funcionality of aws-lambda-go-api-proxy
to Vapor.
Status
Note: Currently this is nothing more than a proof of concept. Use at your own risk. I would like to hear feedback, if you played with this. Please open a GitHub issues for all open ends, you experience.
What I have tested:
- ☑ Routing
- ☑ JSON Coding
- ☐ Cors Middleware
- ☐ Fluent
There are probably tons of other things that we should test. I haven't done much with Vapor so far. Therefore you will need to help me list the things to test.
Examples:
If you test anything, please open a PR so that we can document the state of affairs better. A super small example would be even better. I plan to create some integration tests with the examples.
Usage
Add vapor-aws-lambda-runtime
and vapor
as dependencies to your project. For this open your Package.swift
:
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.0.0")),
.package(url: "https://github.com/fabianfett/vapor-aws-lambda-runtime", .upToNextMajor(from: "0.4.0")),
]
Add VaporLambdaRuntime as depency to your target:
targets: [
.target(name: "Hello", dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "VaporAWSLambdaRuntime", package: "vapor-aws-lambda-runtime")
]),
]
Create a simple Vapor app.
import Vapor
import VaporAWSLambdaRuntime
let app = Application()
struct Name: Codable {
let name: String
}
struct Hello: Content {
let hello: String
}
app.get("hello") { (_) -> Hello in
Hello(hello: "world")
}
app.post("hello") { req -> Hello in
let name = try req.content.decode(Name.self)
return Hello(hello: name.name)
}
Next we just need to run the vapor app. To enable running in Lambda, we need to change the "serve" command. Then we can start the app by calling app.run()
app.servers.use(.lambda)
try app.run()
Contributing
Please feel welcome and encouraged to contribute to vapor-aws-lambda-runtime. The current version has a long way to go before being ready for production use and help is always welcome.
If you've found a bug, have a suggestion or need help getting started, please open an Issue or a PR. If you use this package, I'd be grateful for sharing your experience.
If you like this project, I'm excited about GitHub stars. 🤓
Github
link |
Stars: 62 |
You may find interesting
Releases
vapor-aws-lambda-runtime v0.6.0 - 2020-11-14T22:23:13
⚠️ vapor-aws-lambda-runtime
was moved to the vapor-community.
- The
base64
dependency (swift-extras-base64) has been changed to its new location.
vapor-aws-lambda-runtime v0.5.0 - 2020-10-06T10:29:47
- Fixed the translation between API Gateway request and response and Vapor request and response. (#11) Patch credit @fcobia
vapor-aws-lambda-runtime v0.4.0 - 2020-07-21T12:09:00
New internals and new name!
- The
vapor-aws-lambda-runtime
now runs with theswift-aws-lambda-runtime
under the hood. - We have got a new name to better reflect the compatibility with the official swift lambda runtime.
- The TodoBackend example has been removed for now.
- The README has been adjusted to reflect the changes.
- We have a lot more CI now.
VaporLambdaRuntime v0.3.0 - 2020-05-20T09:52:33
‼️ Breaking change!
This release updates the library to use the Vapor provider pattern. To enable lambda mode use:
app.servers.use(.lambda)
VaporLambdaRuntime v0.2.0 - 2020-01-16T10:46:08
Because of a breaking change in swift-lambda-runtime
this library needs to be updated as well.
For more information see the release notes of swift-lambda-runtime
.
VaporLambdaRuntime v0.1.0 - 2020-01-15T00:24:32
The very first release! Feedback highly welcome.