How do I authenticate with the Google Cloud API without the default credentials for apps or the Cloud SDK?

I am trying to access the Google Cloud API from the AWS Lambda feature, but I do not know how to authenticate. The auth guide in the Google Cloud documentation ( https://cloud.google.com/docs/authentication ) wants me to download the credentials JSON file and use the default credentials for the application, but like someone who has already used the hosting features, knows that you don’t need to manage the server or runtime environment, so Lambda does not allow me to store arbitrary files in the current code environment.

I can use the Cloud SDK locally to get an access token, but it expires, so I cannot use it in my function as a permanent solution.

Is there no way to get an access token that I can use indefinitely in my code to call the Google Cloud API? Is there any other solution?

+4
source share
1 answer

I found how to hardcode the credentials without having to save them in a JSON file. This was in this documentation:

https://googlecloudplatform.imtqy.com/google-cloud-node/#/docs/language/0.7.0/guides/authentication

The following is an example that calls the language API.

var language = require('@google-cloud/language')({
  projectId: '',
  credentials: {
      client_email: '',
      private_key: '',
  }
});

language.detectEntities('Axel Foley is from Detroit').then(function(data) {
  var entities = data[0];
  var apiResponse = data[1];
});
+1

Source: https://habr.com/ru/post/1666365/


All Articles