google-cloud-functions

How to trigger firebase function on all database instances rather than default one?

喜欢而已 提交于 2021-01-29 08:28:50
问题 I have 50 realtime firebase database instances which are all identical. Is it possible to get all my firebase functions to trigger on all instances, rather than just the default instance? I know you can do this exports.myWriteFunction = functions.database.instance('my-secondary-db').ref('path/to/data').onUpdate((snap, context) => { ... }) But I really want to run this function on every instance... 回答1: There is no way to automatically associate a function with all database instances. You will

Firebase - Cloud Functions - make queries on collection

纵然是瞬间 提交于 2021-01-29 08:17:29
问题 Lets say I have two top level collection with users and stories. Now everytime a document from user gets update (only the values username or photoUrl ), I want to update these properties on a document from the story collection. One users doc could look like this (shortened): { username: 'blubber', photoUrl: 'my/photo/path', uid: 'usersUniqueId' } The story doc could look like this (shortened): { username: 'blubber', photoUrl: 'my/photo/path', uid: 'usersUniqueId', sid: 'storiesUniqueId,

How to use telegram webhook on google cloud functions?

主宰稳场 提交于 2021-01-29 07:50:36
问题 I have set up a telegram bot using webhooks in python on google cloud functions. Based on some sample code from the internet I got it to work as a simple echo-bot however the structure is very different to the bots I coded before using long polling: # main.py import os import telegram def webhook(request): bot = telegram.Bot(token=os.environ["TELEGRAM_TOKEN"]) if request.method == "POST": update = telegram.Update.de_json(request.get_json(force=True), bot) chat_id = update.message.chat.id #

Node.js Cloud Function - Stream CSV data directly to Google Cloud Storage file

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 07:49:01
问题 I have a script that can call a RESTful API and retrieve CSV data from a report in chunks. I'm able to concatenate, parse, and display this data in the console. I am also able to write this CSV data to a local file and store it. What I am trying to figure out is how to skip creating a file to store this data before uploading it to GCS and instead transfer it directly into Google Cloud Storage to save as a file. Since I am trying to make this a serverless cloud function, I am trying to stream

Q. Is there a guaranteed max time limit for a Cloud function to execute? considering the occasional cold starts

邮差的信 提交于 2021-01-29 07:31:43
问题 I'm using Google dialogflow to make a Whatsapp Chatbot for a retail store. I'm using cloud functions to carry out certain operations such as create orders, fetch available products, which are common between other endpoints such as websites and apps. As cloud functions undergo cold starts, sometimes the cloud functions take long to respond and dialogflow fails in giving a response as it has a max response time of 5 seconds. Is there any upper limit on the time a cloud function can take to

Using gcloud cli within a cloud function

纵然是瞬间 提交于 2021-01-29 06:21:04
问题 There are great but still limited set of SDK access to GCP APIs within cloud function SDKs. e.g. Node. I want to call gcloud cli within a cloud function. Is this possible? e.g. gcloud sql instances patch my-database --activation-policy=NEVER The goal is nightly shutdown of an SQL instance 回答1: I believe you should use the Cloud SQL Admin API. If you're using the Python runtime for example you'd had 'google-api-python-client==1.7.8' (for example) to your requirements file and on the respective

Calculate time difference within cloud functions

无人久伴 提交于 2021-01-29 06:12:18
问题 In my Cloud Firestore database, always a user is registered, the database stores the time the event occurs: const p = usersReference.add({ ..., registerTime: admin.firestore.FieldValue.serverTimestamp(), ... }); My goal is to create another cloud function that gets a user as input and returns if there is at least 5 days since the user was registered: export const get_user_timeleft = functions.https.onRequest((request, response) => { //useless part of the function... querySnapshot.forEach

admin.auth().verifyIdToken(idToken) Error: Could not load the default credentials whith firebase-admin after to 8.0.0

一笑奈何 提交于 2021-01-29 06:01:35
问题 I've got a problem when i'm trying use middleware in firebase this is my middleware (FBauth) const db = admin.firestore(); const FBAuth = (_req,_res,next) => { let idToken; if(_req.headers.authorization && _req.headers.authorization.startsWith('Bearer ')){ idToken = _req.headers.authorization.split ('Bearer ')[1]; console.log('ID TOKEN ------------>', idToken); }else{ console.error('Nessun Token trovato') return _res.status(403).json({ error: 'non-autorizzato'}); } admin.auth().verifyIdToken

Can't resolve getSignedUrl Promise in Cloud Function

ぃ、小莉子 提交于 2021-01-29 05:25:54
问题 I have been trying to debug a Google Cloud Function that should return a signedUrl for uploading a file to Google Cloud Storage. I have an https cloud function: exports.gcpSecureURL = functions.https.onCall((data, res) => { const bucketName = data.bucket; const fileName = data.filename; let signedUrl = generateV4UploadSignedUrl(bucketName, fileName) .then(value => { console.log("VALUE: ", value); return value }) res.send(signedUrl) }); Value is never reached and signedUrl is always a Promise.

FIREBASE FATAL ERROR: Database initialized multiple times

被刻印的时光 ゝ 提交于 2021-01-29 05:13:58
问题 I have multiple database instances in my firebase app. I am trying to write into three database instances in firebase cloud functions. My understanding by following this document is no need to initialize multiple apps for each database instance. We can initialize one and pass in the database url. As a side note, I have another function with similar kind of functionality where I have trigger event in one database and write data to other database instance and it works fine. import * as