Fork me on GitHub
#aws-lambda
<
2020-01-18
>
jsyrjala05:01:55

If you use something other than InputStream/OutputStream as parameters to function, lambda will try to convert JSON to java classes.

jsyrjala05:01:46

Most likely you’ll want to read input from a InputStream, and then parse it as JSON or END. If you go via lambda’s automatic JSON parsing, you’ll get java classes.

MatthewLisp14:01:54

Thanks @jsyrjala I’ll try it

MatthewLisp20:01:50

@jsyrjala why in your template you state to AWS that you are receiving 2 parameters [InputStream OutputStream] And that you return void I thought I’d receive only one parameter, the InputStream and my output would be a OutputStream

jsyrjala20:01:15

that is how JVM lambdas work if you want to parse request yourself

👍 4
dabrazhe20:01:39

Hi. How can I quickly parse the input parameters in the handler function? It does not seem to a map I can destructure with keywords

(defn -handler
  [this input context] ... )

dabrazhe20:01:44

thanks. when I print the input params it's {operation=echo, message=Hello world!} When I query its type it's java.util.LinkedHashMap. Doesn't look like json : )

jsyrjala20:01:07

here built in jvm lambda framework has parsed incoming json to a Java LinkedHashMap object before calling your handler function.

jsyrjala20:01:59

basically you can either use parameters [InputStream OutputStream] and handle JSON -> clojure datastructure parsing and clojure -> JSON response generation your self. Or use automatic conversion from JSON to Java classes and back to JSON. I have preferred the former.

dabrazhe20:01:34

Interesting approach, thank you. I guess what I really need is clj version of js->clj :keywordize-keys true

dabrazhe21:01:58

Great, ty, will give it try