Skip to content
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

Request never gets to my handler #105

Open
seanhess opened this issue Jul 23, 2021 · 8 comments
Open

Request never gets to my handler #105

seanhess opened this issue Jul 23, 2021 · 8 comments

Comments

@seanhess
Copy link

Hi, thanks for your work on this! My lambda is invoked, but it looks like the request never gets to my handler. I'm getting an Internal Server error.

Here's a copy of the log: My haskell program is run and the wai Application is created (I'm using aws-lambda-haskell-runtime-wai). But there are no messages

FinalFive Main.hs Loaded
"Starting Lambda using API gateway handler 'handler'."
FinalFive Wai application Loaded
START RequestId: 2bb28bf8-1daf-49fe-956e-8a6d88ae72d4 Version: $LATEST
END RequestId: 2bb28bf8-1daf-49fe-956e-8a6d88ae72d4
REPORT RequestId: 2bb28bf8-1daf-49fe-956e-8a6d88ae72d4	Duration: 607.04 ms	Billed Duration: 2923 ms	Memory Size: 1024 MB	Max Memory Used: 44 MB	Init Duration: 2315.74 ms
START RequestId: 3d5dc234-6c7e-400d-954a-71c4e722d666 Version: $LATEST
END RequestId: 3d5dc234-6c7e-400d-954a-71c4e722d666
REPORT RequestId: 3d5dc234-6c7e-400d-954a-71c4e722d666	Duration: 1.67 ms	Billed Duration: 2 ms	Memory Size: 1024 MB	Max Memory Used: 45 MB

The Api Gateway log says Unhandled. Does that mean an unhandled exception or a unhandled request?

{
  "requestTime":"23/Jul/2021:16:04:21 +0000",
  "requestId":"C7lE4jEHIAMEM8Q=",
  "apiId":"flj31jsfu2",
  "resourcePath":"$default",
  "path":"/ballot",
  "httpMethod":"GET",
  "stage":"$default",
  "status":"500",
  "integrationStatus":"200",
  "integrationLatency":"3308",
  "responseLatency":"3313",
  "responseLength":"35",
  "errorMessage":"Internal Server Error",
  "format":"SLS_HTTP_API_LOG",
  "version":"1.0.0",
  "integrationErrorMessage":"The Lambda function returned the following error":"Unhandled. Check your Lambda function code and try again.",
  "responseType":"INTEGRATION_FAILURE"
}

What am I missing?

@seanhess
Copy link
Author

Wait, I had my Main function as a call to runWaiAsLambda, not the generate one, but now that I'm trying to switch to follow your example, I realize that your documentation doesn't match the hackage version. There is no function waiHandler. Can you update the example?

@seanhess
Copy link
Author

It looks like all your documentation is out of date! There is no generateLambdaDispatcher function. The error above comes from attempting to get this to work from only the haddocks. How do you get this to work with the new version? Should I downgrade?

@seanhess
Copy link
Author

seanhess commented Jul 23, 2021

The above error happened when I had the following Main.hs. How do you do this correctly with the latest version?

{-# LANGUAGE OverloadedStrings  #-}
module Lambda where

import Aws.Lambda.Wai
import Aws.Lambda (defaultDispatcherOptions)
import qualified App


main :: IO ()
main =
  runWaiAsLambda
    APIGateway
    defaultDispatcherOptions
    "handler"
    App.app -- :: IO Application

@seanhess
Copy link
Author

This is when the project is configured to use the http api, not the rest api. I was able to get a basic example working simply by switching my project from http to rest.

@dnikolovv
Copy link
Contributor

@seanhess Glad you managed to resolve the issue! The documentation is indeed lacking. Can you open an issue in https://github.com/eir-forsakring/aws-lambda-haskell-runtime-wai?

@seanhess
Copy link
Author

seanhess commented Aug 1, 2021

Perhaps I didn't explain well. This issue is in this repository, it seems that it doesn't support API Gateway Http APIs (As opposed to REST. Http API requests are much cheaper).

It can be reproduced with your simple example, which doesn't use Wai at all, but configure API Gateway to use the http api in place of the rest api.

@dnikolovv
Copy link
Contributor

I get it. We haven't had a use case for that yet, but I'll make a note to implement HTTP API support.

@quyse
Copy link

quyse commented Nov 14, 2021

I initially got the same "Unhandled" error with HTTP gateway. It seems there're two supported payload formats ("1.0" and "2.0") for HTTP gateway, see AWS docs. Apparently HTTP gateway by default uses "2.0". REST gateway uses single unnamed format which seems to be the same as "1.0" format for HTTP gateway.

So, setting the format to "1.0" on AWS side seems to make it compatible with aws-lambda-haskell-runtime and fixes the issue for me. (For clarity, in Terraform I set payload_format_version = "1.0" for aws_apigatewayv2_integration resource).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants