How to connect onprem oracle DB from Micronaut based AWS Lambda

183 Views Asked by At

I am trying to get on micronaut for my Java based serverless (AWS lambda) development. First use case is connect and query onpremise oracle DB (for read only operations) to enrich the data and then call some soap services.

This question is about making Oracle DB call onpremise. I see some references of connection pool based approach on internet (JDBC-hikari etc) which might not needed for lambda app. So what would be best/recommended way to connect/call/close oracle connection using micronaut? Please suggest.

1

There are 1 best solutions below

0
On

Although there will be lots of networking considerations for this to work, I think you're asking specifically about the connection pooling.

You're correct in thinking that your Lambda function probably won't benefit from having many open connections. Depending on the work load you may in fact just want one.

I would recommend that a connection is made during the Lambda init phase. The connection will then persist between invokes. To close the connection before the Lambda execution environment is terminated you can register a runtime shutdown hook.

There is an example in this AWS GitHub repo graceful-shutdown-with-aws-lambda.

Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
        System.out.println("[runtime] ShutdownHook triggered");
        System.out.println("[runtime] Cleaning up");
        // perform actual clean up work here.
        try {
            Thread.sleep(200);
        } catch (Exception e) {
            System.out.println(e);
        }
        
        System.out.println("[runtime] exiting");
        System.exit(0);
    }
});