theam / aws-lambda-haskell-runtime

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

Handler src/Lib.handler does not exist on project #57

Closed 0xgleb closed 4 years ago

0xgleb commented 4 years ago

Hey. I tried following the docs with the person example and I'm getting the following error when trying to test it on AWS.

"Handler src/Lib.handler does not exist on project"

When I try seeing the TH generated code from Main.hs I only see the default case

    main = do runLambda run
    run
      LambdaOptions {functionHandler = functionHandler,
                     contextObject = contextObject, eventObject = eventObject,
                     executionUuid = executionUuid}
      = case functionHandler of {
          _ -> (pure
                  $ Left
                      ("Handler "
                         <> (functionHandler <> " does not exist on project"))) }

My app/Main.hs looks like this:

module Main where

import Aws.Lambda

import qualified Lib

generateLambdaDispatcher

src/Lib.hs:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric  #-}

module Lib where

import qualified Aws.Lambda   as Lambda
import qualified Data.Aeson   as Aeson
import qualified GHC.Generics as Generics

data Person
  = Person
      { personName :: String
      , personAge  :: Int
      }
  deriving (Generics.Generic, Aeson.FromJSON, Aeson.ToJSON)

handler
  :: Person
  -> Lambda.Context
  -> IO (Either String Person)

handler person _context
  = if personAge person > 0
    then pure $ Right person
    else pure $ Left "A person's age must be positive"

Is there a bug or am I doing something wrong?

NickSeagull commented 4 years ago

Hey, thanks for reporting this. Can you upload your project to a github repo so we can check it out?

0xgleb commented 4 years ago

Sure. Will do that tonight

0xgleb commented 4 years ago

https://github.com/gleb-dianov/lambda-world

NickSeagull commented 4 years ago

Thanks! Just checked your project. The runtime looks for files that contain the string handler ::. In your case the type annotation of the handler starts in the next line, that's why it's not being found.

0xgleb commented 4 years ago

Oh, I see. Thanks