Cannot connect to Google Cloud SQL (SQL Server) from Netlify Functions

I am trying to connect to Cloud SQL from my Netlify Serverless Function I created as an API Endpoint through which my flutter front end can interact.

Now the problem is that because netlify does not provide static IP addresses I was forced to use SQL CLOUD PROXY to encounter this authentication issue. Now first thing is that I need to set my json file as Environment Variable GOOGLE_APPLICATION_CREDENTIALS which I am not sure how I can do.

I tried to upload my json key file on github and on netlify’s env variable i set GOOGLE_APPLICATION_CREDENTIALS to key.json file as it is named. Please tell me how to achieve this.

Secondly I need to run the proxy.exe file ,that google provides me, via terminal on netlify which I am also not sure how to do, maybe with a child process, please guide me in that matter as well.

I attempted this by setting my build script in package.json file as: netlify deploy --prod && prox.exe .......

Once I have completed both of these 2 tasks, then I can finally connect to Cloud SQL using my Node JS API endpoint deployed as a Netlify Serverless Function.

Please guide me if I am looking at the right process and If I am then what could be wrong on my end.

To include key.json in your Functions, either import it for example:

import key from '/path-to-key/key.json'

OR

include it in your functions: How to Include Files in Netlify Serverless Functions

Same goes for proxy.exe. However, Netlify Functions run on Linux, not Windows. So .exe would not work.

Okay I will try using linux amd 64 bit version of proxy. Now to execute this proxy file I am thinking about setting my build script in package.json file as netify deploy --prod && ./cloud-sql-proxy my-project:us-central1:my-instance. Please do let me know if its okay or not?

And I think you misunderstood about my key.json file.

I actually need to set the key.json file as my environment variable so I am not really sure how to set a file as an environment variable in netlify…

Environment variables cannot be files - not on Netlify, not on any platform. They’re always strings. So either set the contents of the file as the value of the variable, or the path of the file, depending on your requirements.

Hey I edited the response, can you please revisit it? Thank you

Regarding the build script, I’m not sure what exactly you’re trying. Are you building locally using CLI? Or are you deploying via Git? If it’s the latter, you don’t need the netlify deploy --prod command. I don’t know what the ./cloud-sql-proxy my-project:us-central1:my-instance this is doing, so can’t comment on that.