Fork me on GitHub
#holy-lambda
<
2023-03-31
>
Patrix11:03:20

Has anyone created a (native backend) holy-lambda function that connets to an RDS Mysql database?

Patrix11:03:57

I keep getting this error... (db hostname edited to avoid leaking 🙂 ) {:type com.zaxxer.hikari.pool.HikariPool$PoolInitializationException, :message "Failed to initialize pool: Cannot connect to MySQL server on \n\nMake sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.\n\n", :at [com.zaxxer.hikari.pool.HikariPool throwPoolInitializationException "HikariPool.java" 595]}

Patrix11:03:34

not sure if I've forgotten some dependencies or something else is going on. The same code and config works perfectly on my machine, but doens't work when using sam local invoke or when running in Lambda. same RDS database, same credentials

Karol Wójcik11:03:20

Do you have all the permissions set on Lambda?

Patrix11:03:11

yes I was about to write that, VPC, security groups, and the execution role allowing VPC access are all set

Patrix11:03:57

I wonder if these extra stack trace elements might help... [com.mysql.cj.jdbc.*exceptions*.SQLError createSQLException "SQLError.java" 110]} {:type java.lang.ClassCastException, :message "com.mysql.cj.*exceptions*.CJException cannot be cast to com.mysql.cj.*exceptions*.UnableToConnectException", :at [com.mysql.cj.jdbc.ConnectionImpl createNewIO "ConnectionImpl.java" 825]}], :trace [[com.mysql.cj.jdbc.ConnectionImpl createNewIO "ConnectionImpl.java" 825] [com.mysql.cj.jdbc.ConnectionImpl <init> "ConnectionImpl.java" 448] [com.mysql.cj.jdbc.ConnectionImpl getInstance "ConnectionImpl.java" 241] [com.mysql.cj.jdbc.NonRegisteringDriver connect "NonRegisteringDriver.java" 198] [com.zaxxer.hikari.util.DriverDataSource getConnection "DriverDataSource.java" 121] [com.zaxxer.hikari.pool.PoolBase newConnection "PoolBase.java" 358] [com.zaxxer.hikari.pool.PoolBase newPoolEntry "PoolBase.java" 206] [com.zaxxer.hikari.pool.HikariPool createPoolEntry "HikariPool.java" 477] [com.zaxxer.hikari.pool.HikariPool checkFailFast "HikariPool.java" 560] [com.zaxxer.hikari.pool.HikariPool <init> "HikariPool.java" 115] [com.zaxxer.hikari.HikariDataSource <init> "HikariDataSource.java" 81] [hikari_cp.core$make_datasource invokeStatic "core.clj" 265]

Patrix12:03:27

the part that gets me is that this happens on AWS Lambda or in sam local invoke, so I don't think it's about security groups or IAM roles or VPCs or anything of the sorts... the same code/configuration works when I invoke it directly at the repl or in a test

Karol Wójcik12:03:11

Btw, why you want to use hikari for Lambda? Connection pool doesnt make sense for Lambda environment.

Patrix12:03:18

hmmm it's not a matter of "want" but a matter of "copy pasting my code from other applications to use mysql in this one" 😉

Karol Wójcik12:03:03

Ok, just for your information using connection pool is risky. You will quickly kill the connection limit.

Patrix12:03:23

that explains a lot, I've done that in my dev env already lol

Karol Wójcik12:03:45

I would try without Hikari.

Patrix12:03:17

ok, let me try that first and see how it goes

Patrix06:04:20

okay, after ripping out conman (which was bringing in Hikari) and simplifying a few things, sam local invoke is now working properly. Deploying now to Lambda, fingers crossed.. but already very promising ,thanks for the tip @UJ1339K2B!

Patrix06:04:16

confirmed, DB connection is now working in Lambda as well! can't say "thanks" enough @UJ1339K2B 🙂

Karol Wójcik11:04:58

You are very welcome 😉

👍 2