Fork me on GitHub
#duct
<
2018-06-01
>
scaturr19:06:16

Trying to get database access for the lambda setup going, and when I build, I am getting an exception that seems to boil down to:

Caused by: clojure.lang.ExceptionInfo: Error on key :duct.database.sql/hikaricp when building system {:reason :integrant.core/build-threw-exception ....
    Caused by: java.lang.IllegalArgumentException: Invalid configuration options: (:adapter)

scaturr19:06:39

Curious if anyone else has run into an issue with hikaricp? A cursory google search pointed out that :adapter is not a valid config for hikari any longer?

weavejester19:06:51

What’s the version of hikari-cp you’re using?

weavejester19:06:17

Also what value are you putting in as the :adapter?

scaturr19:06:24

hmmm, using duct.module/sql

weavejester19:06:27

And to what end?

weavejester19:06:45

You can check the exact version of libraries with lein deps :tree

weavejester19:06:00

lein deps :tree | grep hikari for example

scaturr19:06:31

[duct/database.sql.hikaricp "0.3.2"]
     [hikari-cp "1.8.1"]

scaturr19:06:24

And I haven’t actually put anything in :adapter

weavejester19:06:40

Try adding dependencies for [duct/database.sql.hikaricp "0.3.3"]

weavejester19:06:53

And: [hikari-cp "2.4.0"]

weavejester19:06:10

What version of module.sql are you using?

weavejester19:06:46

Okay, that’s the latest stable version.

scaturr19:06:34

after adding those deps, i get a new error

weavejester19:06:34

If adding those dependencies doesn’t work, I’m curious as to what your config looks after a (prep).

scaturr19:06:48

Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.

weavejester19:06:07

So (prep) and then (:duct.database.sql/hikaricp config) at the REPL.

weavejester19:06:14

I think those are the right keys.

scaturr19:06:05

Ok - for lambda I had to do things a little differently:

(let [config  (-> (duct/read-config (io/resource "slack_api/config.edn"))
                  duct/prep)
      handler (-> config
                  (ig/init [:duct.core/handler])
                  :duct.core/handler)]

scaturr19:06:48

This only affects when I’m building for lambda

scaturr19:06:33

I’ll try to log there

weavejester19:06:44

How are you passing in the :jdbc-url key?

weavejester19:06:27

By default it looks for environment variables JDBC_DATABASE_URL or DATABASE_URL

scaturr19:06:30

:duct.database/sql
 {:database-url #duct/env "JDBC_DATABASE_URL"}

scaturr19:06:42

that probably needs to be defined at compile time eh?

scaturr19:06:22

for lambda that is

weavejester19:06:29

I’m not sure how Lambda works, but surely there’s some way of giving it configuration.

scaturr19:06:09

(ns slack-api.lambda
    (:require [ :as io]
              [duct.core :as duct]
              [integrant.core :as ig]
              [clojure.data.json :as json]
              [uswitch.lambada.core :refer [deflambdafn]]))

(duct/load-hierarchy)

(let [config  (-> (duct/read-config (io/resource "slack_api/config.edn"))
                  duct/prep)
      handler (-> config
                  (ig/init [:duct.core/handler])
                  :duct.core/handler)]
  (deflambdafn slack-api.lambda.LambdaFn [is os ctx]
    (with-open [writer (io/writer os)]
      (let [request (json/read (io/reader is :encoding "UTF-8") :key-fn keyword)
            response (handler request)]
        (-> response
            :body
            slurp
            (as-> body (assoc response :body body))
            (assoc :isBase64Encoded false)
            (select-keys [:body :statusCode :headers :isBase64Encoded])
            (json/write writer))))))

scaturr19:06:23

that is how it’s built - and it worked great until i added the db stuff

scaturr19:06:40

i have a jdbc env var set in the lambda environment

weavejester19:06:59

Hm, that should work. Check that it exists with logging, perhaps?

scaturr19:06:34

I don’t have a JDBC_DATABASE_URL set locally though

scaturr19:06:57

compiling the uberjar causes that error

weavejester19:06:35

Ah, because the let clause is defined.

scaturr19:06:40

that fixed it

weavejester19:06:42

Maybe add a delay?

weavejester19:06:00

So you delay the configuration and handler.

scaturr19:06:38

ok, ill give it a try

scaturr19:06:22

ok, that helped it compile, going to throw it up on lambda and see what i get - thanks again for all of your help

scaturr19:06:32

(ns slack-api.lambda
    (:require [ :as io]
              [duct.core :as duct]
              [integrant.core :as ig]
              [clojure.data.json :as json]
              [uswitch.lambada.core :refer [deflambdafn]]))

(duct/load-hierarchy)

(let [deferred (delay (-> (duct/read-config (io/resource "slack_api/config.edn"))
                          duct/prep
                          (ig/init [:duct.core/handler])
                          :duct.core/handler))]
  (deflambdafn slack-api.lambda.LambdaFn [is os ctx]
    (with-open [writer (io/writer os)]
      (let [handler @deferred 
            request (json/read (io/reader is :encoding "UTF-8") :key-fn keyword)
            response (handler request)]

scaturr19:06:54

does this seem correct? - lambda is timing out with this setup

scaturr19:06:03

if it looks correct though i can keep digging

weavejester19:06:06

That… seems fine, I think?

weavejester19:06:33

Might want to pre-prep the configuration to load all the namespaces, maybe?

scaturr19:06:56

as in prep outside of the delay?

weavejester20:06:12

Yeah, maybe. Or run a load-namespaces over it.