Publish to @gcloud/pubsub fails with a decoding fail error (works locally)

I have a function that publishes a JSON to gcloud pub-sub. I could install the dependency “@google-cloud/pubsub” without any issues. However, on the actual publish command, atlas kind of returns me this error message:

Error: 3 INVALID_ARGUMENT: Invalid resource name given (name=). Refer to https://cloud.google.com/pubsub/docs/admin#resource_names for more information.

Now, the code seems to be working locally, without any issues. Let me paste the code here for reference:

async function publishMessage(pubsubPayload, GCPCredentials) {
    const {PubSub} = require('@google-cloud/pubsub');
    const config = {
        "projectId": "my-gcp-project-id",
        "credentials": GCPCredentials
    };
    const pubSubClient = new PubSub(config);
    const topicName = "projects/my-gcp-project/topics/my-topic-name";
    
    try {
        const dataBuffer = Buffer.from(JSON.stringify(pubsubPayload));
        const messageId = await pubSubClient.topic(topicName).publish(dataBuffer);
        console.log(`Message ${messageId} published.`);
    } catch (error) {
        console.error(`Received error while publishing: ${error.message}`);
        console.log(error);
    }
}


exports = function(arg){
  const pubsubPayload = {
      "event": "profile_updated"
  };
  const GCPCredentials =  context.values.get('gcp-auth-credentials');
  publishMessage(pubsubPayload, GCPCredentials);
  return true;
};

It feels almost like Realm Functions do some sort of a decode/encode magic on the data, and it kind of affects the actual data POSTed.

1 Like

Hi @Tony_Thomas - we’re aware of issues with PubSub at the moment, but have a stream of work that is ongoing that should hopefully address this. Realm will transpile dependencies and use our own runtime to execute the function instead of running them on a VM.

1 Like