0
votes

I was going through the documentation for Google Cloud Pub/Sub and I found out that the key file has to be stored in environment variable. https://cloud.google.com/pubsub/docs/quickstart-client-libraries I store want to store it in a config.js file so that I don't have to play with environment variables again when i am deploying it on cloud run. How can I do that?

2

2 Answers

0
votes

My answer isn't exactly what you should expect! In fact, if you run your container on Cloud Run, you don't need a service account key file.

But there is some limitation; I wrote an article on this. And another one article is under review to narrow again these limitations.

So, when you deploy your Cloud Run revision, use the --serviceaccount parameter to specify the service account email to use, and that's all!!


So, to really answer your question, if you have your file set in the config.js, you can manually load the file content and pass it to the lib

const {auth} = require('google-auth-library');
const keys = JSON.parse("YOUR CONTENT");
const client = auth.fromJSON(keys);
0
votes

If you are running on your local windows machine, you can go to the environment variable and create environment variable named - GOOGLE_APPLICATION_CREDENTIALS and set the complete path of service account key json file like - C:/keyfolder/sakey.json. Or you can use command line given in the example of your link.

To get service account key file, you can go to the service Accounts in the GCP console and create service account. If you already have service account, just download the key json file by clicking on ... in action column of Service Accounts.