Open mezzomondo opened 5 years ago
At the moment my biggest achievement is something like:
-- |
-- Module : Main
-- Description : AWS Lambda handler implementation
-- Copyright : (c) Matt Spaulding, 2017
-- License : BSD3
-- Maintainer : matt@mattops.io
{-# LANGUAGE MagicHash, FlexibleContexts, TypeFamilies, DataKinds, TypeOperators #-}
module Main where
import Lambda
import Java
import Java.Collections
data HashMap k v = HashMap (@java.util.HashMap k v)
deriving Class
type instance Inherits (HashMap k v) = '[Map k v]
foreign import java unsafe "get" mapGet :: (m <: Map k v, k <: Object, v <: Object) => k -> Java m v
-- | handler implements the handler function for the RequestHandler object
handler :: (HashMap JString JString) -> Context -> Java (RequestHandler (Map JString JString) (Map JString JString)) (HashMap JString JString)
handler m _ = do
value1 <- m <.> mapGet (toJava "key1")
io $ print value1
return m
-- | Export the handler so it can be referenced by AWS Lambda
-- Use the reference: com.example.LambdaTest::handler
foreign export java "handler"
handler :: (HashMap JString JString) -> Context -> Java (RequestHandler (Map JString JString) (Map JString JString)) (HashMap JString JString)
main :: IO ()
main = return()
I think I'm on the right path but more is still to come...
Hi,
First, thank you for sharing this, I was really hoping to use eta for AWS Lambdas. Still, in the handler, which signature is
handler :: (Map JString JString) -> Context -> Java (RequestHandler (Map JString JString) (Map JString JString)) (Map JString JString)
it's not clear to me how to cope withMap JString JString
, so for example, in the basic Lambda test event input:How can I extract "value1"? What if the input is a more complex JSON?
Thank you again