Skip to content

iam_service.json not found #1224

@bytewiz

Description

@bytewiz

ERROR

I get the following error when I try to use the pubsub client. In my cloud function environment calling pubsub nodejs client.

Warning: iam_service.json not found in any of the include paths

Environment details

  • OS: Cloud functions
  • Node.js version: 12.20
  • npm version: yarn 1.18
  • @google-cloud/pubsub version: 2.10

Steps to reproduce

Trying to instantiate a pubsub client

/**
*  This service account has full access to pubsub on this project.
*  I logged all credentials as well and they are correct.
*/
const sa = functions.config().pubsub.key;

const pubsubClient = new PubSub({
    projectId: sa.project_id,
    credentials: sa, // this is the service account json file (also tried only as { client_email, private_key } same error
});

Call function where client is used:

export const publishToTopic = async (details: { topic: string; body: any }) => {
    try {
        const data = JSON.stringify(details.body);
        const dataBuffer = Buffer.from(data);

        await pubsubClient.topic(details.topic).publish(dataBuffer);

        return;
    } catch (error) {
        console.error(JSON.stringify(error));
    }
};

Get error Warning: iam_service.json not found in any of the include paths

Any help would be appreciated! Due to how cloud functions work I can't seem to use the option of passing a keyFilename path

Note I did try following this: #1000
but it still throws IAM error

Metadata

Metadata

Labels

api: pubsubIssues related to the googleapis/nodejs-pubsub API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions