-
Notifications
You must be signed in to change notification settings - Fork 653
Description
I am trying to connect my NodeJS application to Pub/Sub. Since the production environment is in an AWS instance, I cannot use the default credentials approach. So, my approach is to pass a credentials object with the private key and the client email:
var gcloud_config = {
projectId: process.env.GCLOUD_PROJECT_ID,
credentials: {
client_email : process.env.GCLOUD_CLIENT_EMAIL,
private_key : process.env.GCLOUD_PRIVATE_KEY
}
}According to the docs. This variable is passed as an argument in a class constructor:
constructor(gcloud_config) {
this.topicName = 'cerebro.TrackeableEvent';
this.pubsub = gcloud.pubsub(gcloud_config);
this.topic = this.pubsub.topic(this.topicName);
this.topic.get({
autoCreate: true
}, function(err, data) {
console.log('PubSubTrackeableEventAPI');
console.log('err: ' + err);
console.log('data: ' + data);
});
}When I run locally, everything is OK. There is no err and I can publish to this.topicName. When I run on my staging environment, at AWS, I receive the error Error: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.. I don't know what I am doing wrong. I tried several combinations of the GCLOUD_PRIVATE_KEY. With and without the markers "-----BEGIN PRIVATE KEY-----\n" and "\n-----END PRIVATE KEY-----\n".
Is this a bug or am I doing something wrong that I don't know?