I am trying to configure an SSL connection between PostgreSQL and AWS Lambda. The problem is passing the AWS certificate PEM file to pgjdbc.
I added the PEM file to my resources folder and tried to get it's location with:
Thread.currentThread().getContextClassLoader().getResource("rds-combined-ca-bundle.pem").toString();
And it returns:
file:/var/task/rds-combined-ca-bundle.pem
But if I pass that as the sslrootcert
property, I get an exception:
org.postgresql.util.PSQLException: Could not open SSL root certificate file file:/var/task/rds-combined-ca-bundle.pem.
I then decided to run a code that prints all directories and files names from my Lambda, staring with the current folder, and I get the rds-combined-ca-bundle.pem
file at the current directory.
What's the correct way to get a PEM file from my resources and pass it to pgjdbc then?
So this won't fix the problem described here, but it will solve my issue at configuring pgjdbc.
If you want to pass a Certificate PEM file to pgjdbc, as a resource file, add the following configuration to your properties file:
SingleCertValidatingFactory
accepts other kinds of references to the file, as a classhpath, a file path, an environment variable, a system variable or the Certificate text itself. For more information, see the class docs here.