portkey

Portkey: from REPL to Serverless in one call
baptiste-from-paris 2017-10-01T13:48:34.000011Z

hello all 🙂

baptiste-from-paris 2017-10-01T14:03:07.000109Z

I am trying to make portkey work with the example from the README . Once I depoly/mount the flatten function and I try to call it with query-params, I have a blank page as a respone

baptiste-from-paris 2017-10-01T14:03:46.000004Z

Just to be sure, it should return a string right ?

baptiste-from-paris 2017-10-01T14:29:38.000048Z

because I have this error

{
errorMessage: "Error loading class portkey.LambdaStub",
errorType: "java.lang.ExceptionInInitializerError"
}

baptiste-from-paris 2017-10-01T14:30:21.000043Z

with this code

(defn welcome [] "Hello world !")

(pk/mount! welcome "/welcome")

cgrand 2017-10-01T15:12:19.000028Z

@baptiste-from-paris @viesti ran into a similar issue yesterday, I haven’t had to dig in yet. Are you using it with lein? In which profile did you put portkey ?

baptiste-from-paris 2017-10-01T15:13:14.000067Z

lein => yes lein install then

(defproject port "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "<http://example.com/FIXME>"
  :license {:name "Eclipse Public License"
            :url "<http://www.eclipse.org/legal/epl-v10.html>"}
  :dependencies [[org.clojure/clojure "1.9.0-beta1"]
                 [portkey "0.1.0-SNAPSHOT"]]
  :main ^:skip-aot port.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

baptiste-from-paris 2017-10-01T15:13:31.000011Z

I just generated a lein new app

viesti 2017-10-01T15:15:48.000102Z

looks a bit different to what I ran into, what does the stack trace look like?

baptiste-from-paris 2017-10-01T15:16:12.000101Z

ok, so that’s the route => https://pywts6bswb.execute-api.eu-west-1.amazonaws.com/repl/woo

baptiste-from-paris 2017-10-01T15:16:31.000003Z

and let me find the stacktrace, 1min

viesti 2017-10-01T15:16:58.000073Z

thinking about global leiningen profile in my case now

baptiste-from-paris 2017-10-01T15:18:22.000030Z

Error loading class portkey.LambdaStub: java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
Caused by: java.lang.Exception: Nothing specified to load, compiling:(NO_SOURCE_PATH:0:0)
at clojure.core$throw_if.invokeStatic(core.clj:5808)
at clojure.core$throw_if.doInvoke(core.clj:5795)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.core$load_libs.invokeStatic(core.clj:5924)
at clojure.core$load_libs.doInvoke(core.clj:5910)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$require.invokeStatic(core.clj:5948)
at clojure.core$require.doInvoke(core.clj:5948)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invokeStatic(core.clj:657)
at clojure.core$apply.invoke(core.clj:652)
at portkey.core$bootstrap$fn__17842.invoke(core.clj:187)
at portkey.LambdaStub.&lt;clinit&gt;(LambdaStub.java:23)
... 2 more
Caused by: java.lang.Exception: Nothing specified to load
... 15 more

cgrand 2017-10-01T15:42:52.000036Z

Where do you get the exception? Locally or in AWS?

baptiste-from-paris 2017-10-01T15:54:02.000031Z

aws

baptiste-from-paris 2017-10-01T15:54:18.000048Z

no exceptions/errors locally

cgrand 2017-10-01T16:10:45.000052Z

Oh I see an interesting line: require complaining to be called with no args. Would you mind opening an issue? Merci

viesti 2017-10-01T16:28:25.000046Z

spotted that too but couldn’t explain, wild shot but what Leiningen version are you running on? Could could you try without a ~/.lein/profile.clj, if one is present, for a clean Leiningen repl.

baptiste-from-paris 2017-10-01T16:30:35.000056Z

ok, will do tonight

viesti 2017-10-01T17:02:10.000110Z

apparently I had introduced one breakage at least, which is probably unrelated

viesti 2017-10-01T17:02:37.000004Z

should start working on test on the AWS code to run actual deploys in CircleCI

baptiste-from-paris 2017-10-01T17:39:49.000060Z

@viesti I updated portkey and it’s now working... /cc @cgrand

baptiste-from-paris 2017-10-01T17:40:05.000146Z

thank’s for your time and help

viesti 2017-10-01T17:41:57.000003Z

interesting, meanwhile, the exception was caused by an empty list of requires: https://github.com/portkey-cloud/portkey/blob/master/src/main/clojure/portkey/core.clj#L187

viesti 2017-10-01T17:43:06.000058Z

don’t yet know how that happened, a guard for that case could prevent it but a cause for that would be neat to know

viesti 2017-10-01T17:43:29.000114Z

somewhat warm feeling that it works for you though now 🙂

baptiste-from-paris 2017-10-01T17:47:49.000069Z

I’d really love to understand what’s happening in portkey but I am really lost ^^

baptiste-from-paris 2017-10-01T17:49:18.000046Z

by the way, I’ve seen that you plan to add POST support, any idea what are the challenges with the addition ?

viesti 2017-10-01T17:58:53.000002Z

yesterday landed first version of mounting a ring handler into master with pk/mount-ring!, it takes a var for now, so you have to call (pk/mount-ring! #‘my-handler)

viesti 2017-10-01T17:59:02.000096Z

this would cover POST support

viesti 2017-10-01T17:59:55.000036Z

guess I could close related tickets, and make new one about making this into a macro like pk/mount!

baptiste-from-paris 2017-10-01T18:00:25.000215Z

ok nice, let me try then 🙂

viesti 2017-10-01T18:06:31.000063Z

yes, saw 1.9.0-beta1 as dependency but couldn’t reproduce myself just now, but might still be related

viesti 2017-10-01T18:13:06.000096Z

one fix more, mount-ring! might now work again

baptiste-from-paris 2017-10-01T18:13:46.000070Z

yes, was not mounting ^^

viesti 2017-10-01T18:18:07.000003Z

worked for me, even tried out now 🙂

viesti 2017-10-01T18:18:42.000004Z

yesterday ran into an issue with instaparse, used by compojure, haven’t solved it yet but at least POST requests can be made

baptiste-from-paris 2017-10-01T18:20:41.000028Z

what means /{proxy+} in the path ?

baptiste-from-paris 2017-10-01T18:21:14.000120Z

*in aws api gateway

viesti 2017-10-01T18:24:37.000045Z

it’s a swagger path template (https://swagger.io/specification/#pathTemplating), with a greedy variable (http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-set-up-lambda-proxy-integration-on-proxy-resource), meaning that matches everything after / and binds the match to variable named proxy

baptiste-from-paris 2017-10-01T18:24:57.000041Z

ok, thanks

baptiste-from-paris 2017-10-01T18:25:34.000075Z

why is it usefull ?

viesti 2017-10-01T18:26:55.000046Z

we grab all requests under that path and proxy them to the lambda

viesti 2017-10-01T18:27:52.000103Z

api gateway can have also more specific routes, like the ones created with mount!, the proxy resource allows us to get a more “raw” request into the lambda

baptiste-from-paris 2017-10-01T18:28:05.000030Z

ok

viesti 2017-10-01T18:28:21.000032Z

so that api gateway is more like a reverse proxy sitting in front of the lambda

baptiste-from-paris 2017-10-01T18:30:30.000083Z

ok thanks, so other routes created with mount! should be bypassed right ?

viesti 2017-10-01T18:32:36.000002Z

api gateway matches to the most specific route, so one could have say /{proxy+} with ANY method and a /hello with GET method and /hello would match for a GET request but a POST to /hello would go to the proxy route

baptiste-from-paris 2017-10-01T18:32:56.000043Z

ok thanks !

viesti 2017-10-01T18:34:57.000012Z

not yet sure if portkey should make some decision regarding this, but right now on the path to just deploying and exposing functions 🙂

baptiste-from-paris 2017-10-01T18:35:48.000049Z

that’s amazing what you’ve done !

1😊
viesti 2017-10-01T18:45:23.000015Z

thank you 🙂

baptiste-from-paris 2017-10-01T19:03:23.000058Z

ok, POST working great 🙂 ! trying to add middleware

viesti 2017-10-01T19:42:08.000110Z

would be happy to hear how it progresses 🙂

baptiste-from-paris 2017-10-01T20:00:21.000126Z

by the way, do you know if it’s possible to package a conf file ?

cgrand 2017-10-01T21:04:28.000007Z

@baptiste-from-paris use the :keeps option (takes a list of classes or resources (as strings))

baptiste-from-paris 2017-10-01T21:08:57.000007Z

nice !

baptiste-from-paris 2017-10-01T21:09:01.000044Z

thx

baptiste-from-paris 2017-10-01T21:19:02.000044Z

@cgrand it’s only vars & classes that can be kepts right ? not random file from a resources folder for example

cgrand 2017-10-01T22:42:56.000115Z

@baptiste-from-paris classes and resources; vars I don’t remember having to