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

Example main code in docs out of date #59

Closed nomeata closed 4 years ago

nomeata commented 4 years ago

On https://theam.github.io/aws-lambda-haskell-runtime/03-configuring-the-dispatcher.html we get a main that looks like this

main :: IO ()
main = do
  handlerName <- getHandlerName
  context <- getContext
  input <- getInput
  case handlerName of
    "src/Lib.handler" -> do
      result <- Lib.handler input context
      publish result

but this seems very different from what’s generated by https://hackage.haskell.org/package/aws-lambda-haskell-runtime-2.0.3/docs/src/Aws.Lambda.Meta.Main.html#generate. Are the docs out of date?

(I probably shouldn’t mess with such low level things, but I like to understand the tools that I am using, and avoiding TH is part of that.)

NickSeagull commented 4 years ago

Thanks for pointing this out! That is pseudocode for what's going on, so users could understand more or less what's going on, the docs are not out of date 😊

In the screenshot you can see that it says "a little bit like this" implying it is not the actual one.

screenshot

The code you linked essentially generates a call to runLambda, which is where everything is going on.

I don't think that docs are out of date, but still if you feel like they can improved in any way, feel free to open an issue on it, or reopen this one. Thanks again! 😀

nomeata commented 4 years ago

I indeed didn't see the “a little bit like this” :-)

Maybe some documentation on runLambda when one wants to use it directly might be nice. But I understand it if you don't want to support other workflows bedsides the recommended one.

NickSeagull commented 4 years ago

To be honest I wouldn't wish anyone to do that. runLambda is the interaction point with the AWS Lambda environment, and it receives a function that has to be of some specific form. Adding docs for that would defy the intention of the whole runtime 😬

I'd rather add better TH errors if someone encounters the current ones difficult to understand.

nomeata commented 4 years ago

I disagree. The whole runtime does two things:

  1. Talk to the Lambda Runtime API (fetch requests and delivers responses)
  2. Dispatches to one of multiple handlers.

These seem clearly different tasks to me, and wanting to do 1 doesn’t mean you want 2 as well (Think wai and wai-routes).

For example a lambda that has only a single handler doesn’t need 2.

Or am I missing something?

NickSeagull commented 4 years ago

I see what you mean here, in that case it'd be probably better to provide a singleHandler function or something like that. A user could call that like:

main = singleHandler foo

-- actual handler
foo = ...