I'm using psycopg2 inside an AWS lambda function and would like to connect to cockroachdb.
To connect locally I just add my cockroackdb (same for vanilla postgres) root.crt file to my machine in the default $HOME/.postgresql/root.crt location.
However, since I'd like to connect via a Lambda function, I'd rather not be deal with a file and instead use an ENV variable configured at the function level in AWS.
I've searched around and could not find a solution to specify because it appears that typically psycopg2 sslrootcert expects a file path.
Ideally I'd like to be able to do something like this:
cert = base64.b64decode(os.environ["ROOT_CRT"]).decode("ascii")
conn=psycopg2.connect(
dbname="test",
user="postgres",
password="secret",
host="127.0.0.1",
port="5432",
sslrootcert=cert)
Where sslrootcert= is pointing to a python variable based on the ENV variable where the cert was pasted to bypass a file based approach.
Any suggestions?