Environment variable difference in Netlify Dev vs. Production

Hi,

I am building a site using Gatsby & Netlify with Netlify Build. The site uses Netlify Functions to interact with Google Sheets via Google’s API.

Google’s API requires me to configure an environment variable (called GOOGLE_APPLICATION_CREDENTIALS) that has the path to the json credentials file provided by Google, which I’ve done using Netlify’s dashboard.

Setting this environment variable as something like “./myFunctionsFolder/myFunctionName/my_credentials_file.json” works well locally with Netlify Dev, but fails in production. The function call in production outputs an error message saying that the file does not exist:

Error: The file at ./myFunctionsFolder/myFunctionName/my_credentials_file.json does not exist, or it is not a file. ENOENT: no such file or directory, lstat ‘/var/task/functions’.

Is there a way to resolve this difference between dev vs. production while keeping the credential file private?

Thank you!

(if needed - Google’s node js API: GitHub - googleapis/google-api-nodejs-client: Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.)

Hi @kompound,

Not sure how your prepping your function for deployment, but I recommend doing the zip method instead of bundling. I believe that will work for you. You just need to have your credentials json file in the same directory as the function, and the node_modules also in that directory.