Giter VIP home page Giter VIP logo

vapor-aws-lambda-runtime's Introduction

vapor-aws-lambda-runtime

Swift 5.2 Vapor 4 github-actions codecov

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.Requests and Vapor.Responses 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. ๐Ÿค“

vapor-aws-lambda-runtime's People

Contributors

0xtim avatar fabianfett avatar fcobia avatar pschmiedmayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vapor-aws-lambda-runtime's Issues

Returning Protobuf binary data seems to truncate in AWS

Have managed to get a nice API proof of concept for JSON responses, but having a hard time doing it for protobuf data.

Already wrote the code to have my vapor API return protobuf data with the appropriate contentType of "application/protobuf" based on whether the client sends an Accept header with application/protobuf, all that works when I run my vapor API locally (both running via docker or just swift run).

But trying to make use of that when the service is running in AWS doesn't work.

After a bit of poking around, I've figured out that the aws RestApi declaration in AWS needed a declaration for "binary_media_types".

For example:
binary_media_types=["application/protobuf"]

But it still does not work.

As far as I can tell, it might just require a modification to check the contentType for application/protobuf before creating the APIGateway Response, in these files here:

if let string = response.body.string {

if let string = response.body.string {

Just wanted to raise it as a possible feature request, think it would be pretty cool.
If its already possible to get this working somehow, then I would greatly appreciate any hints or information that might help.

Thanks for making such an awesome library !

Local Lambda Debugging

The swift-was-lambda-runtime project has added the ability to run a local lambda server by setting the LOCAL_LAMBDA_SERVER_ENABLED environment variable to "true." I tried this with the Vapor integration and it does not seem to work.

It would be nice if this worked so I could run / debug inside Xcode on my Mac.

If you do not have time to do it, I have looked a little and am not sure where to look. Do you know where I would start to look into fixing this?

Help with how to use it - Possibly a bit more info in the Readme

Experimenting with this, and setting up a vapor service using pulumi scripts in aws.
In terms of what's needed in the swift vapor code, is it enough to just do this here:

app.servers.use(.lambda)

Or is there anything else I would need to do per endpoint, to get this working?

Follow Vapor 4's provider pattern

@tanner0101 suggested:

Creating a community package that follow's Vapor 4's provider pattern could be a good next step
Something like:

import Vapor
import Lambda

let app = Application(...)
defer { app.shutdown() }

app.lambda.enable()

try app.run()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.