Introduction
We'll deploy a PubSub triggered Functions that prints out a Hello World message to the Cloud Logs.
Further reading:
This quickstart demonstrates how to setup a PubSub triggered Cloud Function using the Firebase SDK for Cloud Functions.
We'll deploy a PubSub triggered Functions that prints out a Hello World message to the Cloud Logs.
Further reading:
Clone or download this repo and open the quickstarts/pubsub-helloworld
directory.
Create a Firebase Project on the Firebase Console.
Set up your Firebase project by running firebase use --add
, select your Project ID and follow the instructions.
You need to have installed the Firebase CLI. If you haven't run:
npm install -g firebase-tools
Doesn't work? You may need to change npm permissions.
First you need to install the npm
dependencies of the functions:
cd functions && npm install; cd ..
This installs locally the Firebase Admin SDK and the Firebase SDK for Cloud Functions.
Deploy to Firebase using the following command:
firebase deploy
This deploys and activate the PubSub hello World Functions.
The first time you call
firebase deploy
on a new project with Functions will take longer than usual.
Once deployed, to try the sample use the gcloud
CLI to publish a message to the topic-name
topic:
gcloud alpha pubsub topics publish topic-name --message='YourName'
Open the Functions logs in the Firebase Console, you should see a messages that reads "Hello YourName".
Then you can also publish a message to the another-topic-name
topic using JSON data:
gcloud alpha pubsub topics publish another-topic-name --message='{"name":"YourName"}'
Open the Functions logs in the Firebase Console, you should see a messages that reads "Hello YourName".
Last you can also publish a message to the yet-another-topic-name
topic using JSON data:
gcloud alpha pubsub topics publish yet-another-topic-name --attribute name=YourName
Open the Functions logs in the Firebase Console, you should see a messages that reads "Hello YourName".
We'd love that you contribute to the project. Before doing so please read our Contributor guide.
© Google, 2016. Licensed under an Apache-2 license.