Welcome! Please see the About page for a little more info on how this works.

0 votes
in Ions by
edited by

Hello! After hearing the talks and reading the tutorial and documentation, I was under the impression that ions receive their requests in a ring-like format, and that we can "wire a web handler to a single function, using a routing library such as Compojure or pedestal."1

On one hand, this seems to be true with standard ion lambdas, but these are not exposed to the web. OTOH if we want to expose our web service, we need to write a web handler that we'll ionize. When we do that, the requests coming in lose their ring-like shape, and only expose the following keys:


With that, our router (reitit backed by ring) fails.

I have seen different examples on the web where some router is exposed behind a single web handler, the most promising of which being probably Replion (look at the code) (and he uses reitit and ring and seems to have more success than us) and Pedestal Ions Sample (but Pedestal works in a relaxed ring context).

So my question is: is there something obvious that I don't understand? Are there more working examples? Some people seem to write adapters to transform the requests to make them more ring-like. Are they doing the right thing, or are we all missing something?

For example, here's a very naive adapter:

(defn get-path [req]
  (let [s (get-in req [:datomic.ion.edn.api-gateway/data :requestContext :stage] "stg")
        p (get-in req [:datomic.ion.edn.api-gateway/data :requestContext :http :path] "/")]
    (get (str/split p (re-pattern (str "/" s))) 1 "/"))) ; get rid of stage leading path!

(defn req->ring-req [req]
  (assoc req
         :protocol (get-in req
                           [:datomic.ion.edn.api-gateway/data :requestContext :http :protocol] "HTTP/1.1")
         :remote-addr (get-in req [:headers "host"] "example.com")
         :request-method (keyword
                           (get-in req [:datomic.ion.edn.api-gateway/data :requestContext :http :method] "GET")))
         :uri (get-path req)))

(defn app
  "Web handler that returns the app's responses for each web request."
  (let [sta (start! arg)
        req (req->ring-req arg)
        ret ((handler/app) req)]

Another related question is: what is the :integration key on lambda configurations? Why does "nobody" use it, except Stu's slack event handler? What does it do? We tried setting it and didn't seem to observe an impact.


Please log in or register to answer this question.