Some Cloud Functions formats are not deployed

Viewed 108

I guess it must be a silly reason but I don't understand why from these 2 Cloud Functions, only the first one is recognized and deployed when I run the following command:

firebase deploy --only "functions:test1,functions:test2"

The first function that is a simple CRON is well deployed:

exports.test1 = functions
  .pubsub.schedule('2,7,12,17,22,27,32,37,42,47,52,57 * * * *')
  .timeZone('Europe/Paris')
  .onRun((context) => {
    console.log('test1');
});

The second one that receives data from a PubSub is never deployed:

exports.test2 = (message, context) => {
  const name = message.data
    ? Buffer.from(message.data, 'base64').toString()
    : 'World';

  console.log('test2');
};

Do I have to use the gcloud commands to deploy the second one?

1 Answers

The second function test2 which receives data from Pub/Sub is triggered by a Pub/Sub topic. Cloud Functions for Firebase with Pub/Sub trigger which you can find here. As per the linked documentation you should mention the Cloud Functions for Firebase to be triggered by the Pub/Sub topic inside the functions code. The firebase deploy command does not have an option to specify the trigger topic while running the command. So if you want to deploy both the functions at a time then you should change your code to include the trigger topic as following -

exports.test2 = functions.pubsub.topic('topic-name').onPublish((message) => {

  const name = message.data
    ? Buffer.from(message.data, 'base64').toString()
    : 'World';
      
  console.log(name);   
  });

topic-name is your Pub/Sub topic name.

If you don’t want to deploy both the functions at a time, then you can deploy the test2 function using gcloud with the code you have written and specify the trigger topic name while running the command, as mentioned here.

Related