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

Non-JSON payloads #77

Closed lrworth closed 4 years ago

lrworth commented 4 years ago

We are trying to deploy a SAM app to respond to Slack slash-commands. When you deploy a AWS::Serverless::Function with an Api event source, you get an API Gateway with a proxy lambda — so HTTP POST requests are relayed verbatim to the Lambda under apiGatewayRequestBody. Slack posts parameters as application/x-www-form-urlencoded, but ApiGatewayRequest's FromJSON instance requires the body to be JSON-formatted.

This all means that there is no (simple) way to use aws-lambda-haskell-runtime with AWS SAM to receive the Slack payload. I've forked this repository to add the functionality I need, but I am not convinced my solution will work for everyone so I'm not willing to submit a PR yet.

NickSeagull commented 4 years ago

Hey, thanks for pointing this out!

This for sure is important. Yes, the 80% of the cases are JSON-formatted bodies, but it is necessary to support the other 20%. What did you do in your fork?

lrworth commented 4 years ago

I added

newtype RawApiGatewayRequest = RawApiGatewayRequest (ApiGatewayRequest Text)

with a different FromJSON instance, and exported LambdaError and RunCallback so I could write my own main rather than using the TH-generated one. (The generated one bakes in JSON decoding).

lrworth commented 4 years ago

Well, I made a PR anyway!

NickSeagull commented 4 years ago

I see, let's discuss over there!

NickSeagull commented 4 years ago

This was added on version 3.0.0, closing this