question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove misleading mention of composing env variables that only works via `.env` files

See original GitHub issue

Update: See problem in https://github.com/prisma/docs/issues/2835#issuecomment-1026293087

Discussed in https://github.com/prisma/prisma/discussions/11453

<div type='discussions-op-text'>

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=longbase64string

I’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</div>

The reason I’m moving this to an issue is that due to the nature error, I believe this may be a bug.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Apr 19, 2022

That is completely unrelated to the env var problem and is probably related to the bundler you are using or something like that. Please open a new bug report issues in prisma/prisma about this if you can reproduce this. Thanks.

1reaction
yannickglostercommented, Jan 28, 2022

I hadn’t though of testing that @janpio, I just did and I got the same error:

[GET] /api/tournaments
17:56:15:24
2022-01-28T17:56:15.974Z	4b670608-cb13-48cf-aca0-26f63e32b1f7	ERROR	PrismaClientInitializationError: Can't reach database server at `IDONOTEXIST`:`3306`
Please make sure your database server is running at `IDONOTEXIST`:`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-28T17:56:15.975Z	4b670608-cb13-48cf-aca0-26f63e32b1f7	ERROR	PrismaClientInitializationError: Can't reach database server at `IDONOTEXIST`:`3306`
Please make sure your database server is running at `IDONOTEXIST`:`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: 4b670608-cb13-48cf-aca0-26f63e32b1f7 Error: Runtime exited with error: exit status 1
Runtime.ExitError

The server is reachable, as mentioned previously, when I don’t include SSL parameters, it informs me that I need to use SSL to connect to the server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove misleading mention of composing env variables that ...
Variables stored in .env files can be expanded using the format specified by dotenv-expand. ... fix: dotenv-expand only works for the .env file...
Read more >
How to Use Environment Variables in a .env file to fill out other ...
I would like to specify these in an environment variable and reuse those variables to fill out the other environment variables. Here is...
Read more >
Stop Using .env Files Now! - DEV Community ‍ ‍
Solving: 1. Storing the .env file. With a config server, all the secrets are centralized in one place, encrypted, and can only be...
Read more >
Overriding One Single Value in Your Docker-Compose .env File
Using a .env file is one of the many ways fo configure Docker images and containers. If you are using docker-compose, the values...
Read more >
Environment variables in Compose | Docker Documentation
If you have multiple environment variables, you can substitute them by adding them to a default environment variable file named .env or by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found