theam / aws-lambda-haskell-runtime

⚡Haskell runtime for AWS Lambda
https://theam.github.io/aws-lambda-haskell-runtime/
Other
270 stars 48 forks source link

Native API Gateway support #63

Closed dnikolovv closed 4 years ago

dnikolovv commented 4 years ago

generateLambdaDispatcher now takes a DispatcherStrategy that allows you to specify how you would like to use your lambda (UseWithApiGateway or StandaloneLambda).

What changes when you pass in UseWithApiGateway:

  1. The expected handler format becomes
handler :: ApiGatewayRequest req -> Context -> IO (Either (ApiGatewayResponse error) (ApiGatewayResponse res))

There will be compiler errors if you forget to wrap your request and response, so this is perfectly safe.

  1. You can return custom headers and status codes through ApiGatewayResponse, as well as access request metadata through ApiGatewayRequest.

  2. The ApiGatewayResponse wrapper will not be visible when returning responses, errors. The gateway looks like a regular API.

  3. Impure errors (e.g. error) will be propagated upwards by default, meaning you'll get back the stacktrace as a 500 response. This can be disabled by switching the propagateImpureExceptions flag in the DispatcherOptions passed to generateLambdaDispatcher.

  4. ScopedTypeVariables is now a required extension where you use generateLambdaDispatcher.

Nothing significant should've changed if you pass in StandaloneLambda.


I have tried to adhere to the current codebase style, but I may have messed some stuff up. Be liberal with comments.

I guess we'd also need to benchmark this thing. If someone could help with that, that'd be great!

I've also bumped the version to 2.0.5. Not sure if that makes sense as there are breaking changes, but it's up to you to decide.

I guess it would also be good to have some example projects set up to compliment the documentation (which will also need to be updated). I guess I could take up on that.

NickSeagull commented 4 years ago

Thanks!!