-
Notifications
You must be signed in to change notification settings - Fork 49
Enable users to call runLambda
#78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Since version One thing I don't like about this In my opinion, this feature is a great use case for the About having a custom main, it'd be nice to have as some very advanced opt-int feature, but since the introduction of Edit: You could've avoided the |
You mean these ones? We didn't realise that they existed, and personally I think they're a bit spooky and magical. It might be better to do some kind of |
@dnikolovv I see these things were added just after we started development — great minds think alike. In that case, I believe all that is missing from |
@endgame Yeah, I thought that it's a bit shady when adding those, but it seemed to make perfect sense that someone wanting the raw request body would just do Anyhow, as @lrworth mentioned, those are very new and it's likely you didn't have them at the time of investigating the issue. About the content dispatching, this is exactly what I meant by having it in the About the main thing, @NickSeagull is the one that takes the decisions. The only concern I have about it is that people will use it to implement interesting features instead of submitting an issue and getting them into the runtime itself, but we can't have the best of all worlds :( |
What if you exposed thing in a public |
Yeah I guess that'd be the best thing to do. |
I've generated a few thoughts via sleep and a shower. About a month ago AWS SAM gained the ability to build and deploy [Haskell] projects with this command: sam build && sam deploy only requiring you to write a Makefile containing a build target for each
I suppose in my ideal world, (I know text can come across as sterile and harsh but I do really appreciate the work you guys have put into this package already; I want as much as you to see this package flourish and become the go-to for dead-simple Haskell deployments to Lambda.) |
`runLambda` itself was exported from this package, but not the types it depends on.
@dnikolovv I've updated this PR to allow users to call |
runLambda
@lrworth I'm all in for a custom main. The concerns I have are superficial. @NickSeagull can merge this, I'm just a contributor. |
First of all, thanks everyone for taking part in the discussion. Things like this make the project grow in a good way 😃 Regarding the As an example, think that you are making an app that consumes a huge JSON from some legacy service that essentially is an array of customers that you want to register in your new system and finally notify them.
If we were to use On the other hand, with the Of course, this approach is not perfect, and the minimum would be that Let's do one thing, what do you think of renaming |
Thanks for your response @NickSeagull 😄 There is no need to create a new project for each Lambda, only a separate executable target in the cabal file, and with common stanzas this becomes quite manageable (about 3 lines per target). In fact what you described (3 interacting lambdas connected with SQS) is exactly what we are doing and this design works well so far. In any case, there's probably a better solution for us than just using |
But how do you do that, if the executable needs to be called With this change it'd be very easy to implement the |
AWS' Each function invokes a distinct target, and you build the relevant component and then copy it across to |
The original description of this PR related to handling JSON payloads, but as of 3.0.0 this change was not needed; however I would still like to be able to call
runLambda
without usinggenerateLambdaDispatcher
, and the only thing stopping this is thatLambdaError
andToLambdaResponseBody
are not exported.This PR exports those types.
Old description
See #77
This PR is a draft as it is primarily for discussion.
In order to handle non-JSON payloads to the lambda, this PR:
RawApiGatewayRequest
andRawApiGatewayResponse
which are newtype wrappers overApiGatewayRequest
andApiGatewayResponse
but with FromJSON instances that don't parse the body;main
routine so that we can avoid the JSON decoding baked intogenerateLambdaDispatcher
; andThe second point I would like to discuss further. I did this by necessity to get my project working, but now that I have it I don't want to go back to using
generateLambdaDispatcher
even if it did support non-JSON payloads, because of the following benefits:main
I can point to and understand.main
allows for initialisation setup, like reading environment variables and setting up amazonka, before the main loop commences.runLambda
with more specific types, such asrunSqsLambda :: AWS.Env -> (SqsPayload -> ExceptT String AWS.AWS String) -> IO ()
which removes any doubt about what type the handler function has to be.Moreover, with the addition of abstractions like
runSqsLambda
the number of keystrokes saved by usinggenerateLambdaDispatcher
is negligible at best; compareversus
(I also added a
shell.nix
so I could develop this library - take it or leave it 😊)