-
Notifications
You must be signed in to change notification settings - Fork 856
Description
Update: See problem in #2835 (comment)
Discussed in prisma/prisma#11453
Originally posted by yannickgloster January 27, 2022
Following prisma/prisma#1673, I converted the SSL Certificate that I needed from here Azure Database for MySQL into base64 to store it in as an environment variable that I can then load in into the tmp folder on the serverless function.
I do this when I create my prisma client:
/lib/prisma.js
import { PrismaClient } from "@prisma/client";
const fs = require("fs");
const path = "/tmp";
try {
if (fs.existsSync(`${path}/BaltimoreCyberTrustRoot.crt.pem`)) {
// do nothing
} else {
// creates crt.pem file from ENV
fs.mkdirSync(path, { recursive: true });
fs.writeFileSync(
`${path}/BaltimoreCyberTrustRoot.crt.pem`,
Buffer.from(process.env.CRT_PEM, "base64").toString("ascii")
);
}
} catch (err) {
console.error(err);
}
const prisma = global.prisma || new PrismaClient();
if (process.env.NODE_ENV === "development") global.prisma = prisma;
export default prisma;Locally this works as expected, and when I check on the API endpoint, the file exists correctly
import fs from "fs";
export default async function handler(req, res) {
const files = fs.readFileSync(`/tmp/BaltimoreCyberTrustRoot.crt.pem`);
res.status(200).json({ files: files.toString() });
}My environment variables look like this:
SSL_CERT_PATH=/tmp/BaltimoreCyberTrustRoot.crt.pem
DATABASE_URL=mysql://user:pass@lserverip:3306/registration?sslcert=${SSL_CERT_PATH}&connect_timeout=300
CRT_PEM=longbase64stringI'm able to successfully connect to the DB when I use those variables locally, but when deployed I get the following error when I go to make a request to the DB.
2022-01-27T23:22:08.847Z c63d91bb-ae49-40c3-95dd-c20a224d3f4d ERROR PrismaClientInitializationError: Can't reach database server at `IP OF SERVER`:`3306`
Please make sure your database server is running at `IP OF SERVER`:`3306`.
at cb (/var/task/node_modules/@prisma/client/runtime/index.js:38697:17)
at async handler (/var/task/.next/server/pages/api/tournaments.js:60:25)
at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils.js:102:9)
at async NextNodeServer.handleApiRequest (/var/task/node_modules/next/dist/server/base-server.js:1076:9)
at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:963:37)
at async Router.execute (/var/task/node_modules/next/dist/server/router.js:222:32)
at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:1103:29)
at async NextNodeServer.handleRequest (/var/task/node_modules/next/dist/server/base-server.js:319:20)
at async Server.<anonymous> (/var/task/___next_launcher.js:32:9) {
clientVersion: '3.8.1',
errorCode: undefined
}
2022-01-27T23:22:08.847Z c63d91bb-ae49-40c3-95dd-c20a224d3f4d ERROR PrismaClientInitializationError: Can't reach database server at `IP OF SERVER`:`3306`
Please make sure your database server is running at `IP OF SERVER`:`3306`.
at cb (/var/task/node_modules/@prisma/client/runtime/index.js:38697:17)
at async handler (/var/task/.next/server/pages/api/tournaments.js:60:25)
at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils.js:102:9)
at async NextNodeServer.handleApiRequest (/var/task/node_modules/next/dist/server/base-server.js:1076:9)
at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:963:37)
at async Router.execute (/var/task/node_modules/next/dist/server/router.js:222:32)
at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:1103:29)
at async NextNodeServer.handleRequest (/var/task/node_modules/next/dist/server/base-server.js:319:20)
at async Server.<anonymous> (/var/task/___next_launcher.js:32:9) {
clientVersion: '3.8.1',
errorCode: undefined
}
RequestId: c63d91bb-ae49-40c3-95dd-c20a224d3f4d Error: Runtime exited with error: exit status 1
Runtime.ExitError
If I remove the SSL information from my DB connection string, I get an error stating that I need to provide SSL information to continue.
Server error: `ERROR 28000 (9002): SSL connection is required. Please specify SSL options and retry.\u0000'
Is there something I'm doing wrong here?
Thanks in advance
The reason I'm moving this to an issue is that due to the nature error, I believe this may be a bug.