Fork me on GitHub
#aws
<
2016-11-10
>
cfleming15:11:40

Developing CLJS lambda functions using cljs-lambda and associated projects is very nice.

cfleming15:11:13

API gateway is the big missing piece, but I can hack that for the meantime.

bja15:11:12

I've always thought it would be nice to use one of the data-based routing libraries and retargeting it to API gateway

bja15:11:57

so that you had a good story for local development as well as being able to skip shed color choices for the api (IMO the least interesting piece)

cfleming15:11:14

@bja Which routing libraries do you mean?

cfleming15:11:27

The issue with API gateway is all the template malarkey

bja15:11:13

I just mean, to declare what you want your api to look like using the same syntax/data as some routing library, and then let the library build out the templates for you

bja15:11:23

I don't think such a thing exists

cfleming15:11:33

No, it would certainly be nice.

cfleming15:11:12

Any preference for routing library? I’m not familiar with them, and I might add something like that to cljs-lambda depending on how difficult it turns out to be

cfleming15:11:26

Do they support e.g. mapping parameters to JSON etc?

bja15:11:32

I don't have a particular preference, but one of the ones that is data-based instead of macro-based is probably a good start

bja15:11:55

what do you mean mapping parameters to json?

cfleming15:11:38

So with my existing API, it’s for a webhook that only sends POST params. I need to create a template that maps that to a JSON doc, since lambda receives JSON.

bja15:11:03

one thing I could imagine would be doing something like this (using compojure-api syntax):

(GET "/add" request
           :query-params [num :- s/Int]
           (ok (inc num)))

bja15:11:55

theoretically, you could even use compojure-api (or ring-swagger, which is what it uses under the hood) to generate the swagger spec for that route for you

bja15:11:04

and use that to build the api gateway definition

bja15:11:13

then you can take the body and destructuring it generates, and turn that into a lambda

bja15:11:59

with the upside of, if you did it "right", you might be able to use compojure-api locally for development testing

bja15:11:22

(compojure-api is just a convenient example here since it already generates a swagger json/yaml spec for you)

bja15:11:33

there would obviously be a couple limitations (i.e. your whole routes have to defined at compile time)

cfleming15:11:54

compojure-api is macro-based though, right?

bja15:11:10

the latest version uses a macro sugar layer on top of maps

bja15:11:27

I'm actually still on their old 0.2x.x release at my job 😞

bja15:11:40

#ring-swagger might know more

cfleming15:11:45

Doesn’t look like it: “all compojure-api route functions & macros return compojure.api.routes/Route-records”...

bja15:11:07

well, s/map/Route record/

cfleming15:11:46

Ideally I’d be able to define the templates somewhere static so that the cljs-lambda lein plugin could build things based on the definition.

bja15:11:51

couldn't the cljs-lambda lein plugin just invoke whatever compojure.api.routes/get-routes and use the resulting info?

cfleming15:11:02

Maybe, I’m not sure.

bja15:11:04

(along with the route records)

bja15:11:53

I don't know if their wrap-routes stuff can be replaced or includes the right meta to lookup source code so that you could compile the bodies to lambdas

bja16:11:12

but today is the first day of my vacation, so spinning up a project and a repl!

cfleming16:11:37

I think that would be too much magic - I’d rather it referenced the lambda by name.

cfleming16:11:43

For my taste, at least.

bja16:11:55

one of the other routing libraries like bidi might be a good fit then

cfleming16:11:15

And it would be a large change to the way things work right now AFAIK, but I’m not that familiar with it yet.

bja16:11:16

that one is more data based

bja16:11:06

i.e. something like this:

["/" {"blog" {:get
                {"/index" (lambda-fn :my-index)}}
              {:request-method :post :server-name ""}
                {"/zip" (lambda-fn :zip)}}]

bja16:11:51

that was just adapted from an example at https://github.com/juxt/bidi

cfleming16:11:23

Right, something like that would be preferable I think.

bja16:11:03

it does look like if you can find something with output to swagger 2.0, you can directly import that into API Gateway: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html

bja16:11:53

which seems at least like it's a bit more well-trodden of a path than trying to speak their rest api