google-cloud-functions

Is this the correct way to write if..else statement in cloudbuild.yaml file?

戏子无情 提交于 2020-07-09 11:50:44
问题 I am trying to deploy a cloud function using cloudbuild.yaml. It works fine if I don't use any conditional statement. I am facing an error when I execute my cloudbuild.yaml file with if conditional statement. What is the correct way to write it. Below is my code: steps: - name: 'gcr.io/cloud-builders/gcloud' id: deploy args: - '-c' - 'if [ $BRANCH_NAME != "xoxoxoxox" ] then [ 'functions', 'deploy', 'groups', '--region=us-central1', '--source=.', '--trigger-http', '--runtime=nodejs8', '--entry

Is “ finished with status: 'crash' ” normal for Cloud Functions?

强颜欢笑 提交于 2020-07-08 11:13:22
问题 I tried Google Cloud Functions with Python and there was a problem with running it. It said: Error: could not handle the request I checked the logs, but there was no error, just a log message: Function execution took 16 ms, finished with status: 'crash' When I simplified the function to a printout then it worked properly. Then I added raise Exception('test') before the printout to see if the exception is going to Stackdriver Errors, but it didn't, I got the finished with status: 'crash'

Adding multiple documents in cloud functions

删除回忆录丶 提交于 2020-07-08 03:42:33
问题 I want to add multiple documents in the sampleData collection? Also, there is a serverTimeStamp property on the sampleData, how can I add this as well. sampleData looks like: name: String serverTimeStamp: serverTimeStamp tags: Array [] exports.newUserSignup = functions.auth.user().onCreate((user) => { const p1 = admin.firestore().collection('users').doc(user.uid).collection('score').add({ gems: 0, }) const p2 = admin.firestore().collection('users').doc(user.uid).collection('sampleData').add({

Firebase querying by date not working after deploy

﹥>﹥吖頭↗ 提交于 2020-07-08 03:24:18
问题 I'm working on a REST API with firebase and I'm querying some data by date. It works fine on the localhost but after deploy, it does not! I'm also using momentjs to help to deal with dates. The date field of my document is a timestamp. Here is how I'm doing my query: const documents = await admin.firestore() .collection('orders') .where('date', '>', moment('2020-06-23')) .where('date', '<', moment('2020-06-24')) .get() I have also done the same thing with Date() instead of momentjs const

Firebase querying by date not working after deploy

两盒软妹~` 提交于 2020-07-08 03:24:17
问题 I'm working on a REST API with firebase and I'm querying some data by date. It works fine on the localhost but after deploy, it does not! I'm also using momentjs to help to deal with dates. The date field of my document is a timestamp. Here is how I'm doing my query: const documents = await admin.firestore() .collection('orders') .where('date', '>', moment('2020-06-23')) .where('date', '<', moment('2020-06-24')) .get() I have also done the same thing with Date() instead of momentjs const

HTTP POST Google Cloud Functions NodeJS

戏子无情 提交于 2020-07-07 06:02:42
问题 How do I write a Google Cloud Function that will receive a HTTP request and then send a HTTP POST request to a different endpoint? For example, I can send the HTTP trigger to my cloud function (https://us-central1-plugin-check-xxxx.cloudfunctions.net/test). I am using exports.test = function helloWorld(req, res){} to process the data received. And then I want to send the processed data with a HTTP POST request to a different endpoint. By far I have tried sending HTTP POST with node-webhooks,

How can make folder with Firebase Cloud Functions Storage

自古美人都是妖i 提交于 2020-07-06 09:17:26
问题 how can I make folder "posts" ? bucket --> gs://app.appspot.com/posts code exports.generateThumbnail = functions.storage.object() .onChange(event => { const object = event.data const filePath = object.name const fileName = filePath.split('/').pop() const fileBucket = object.bucket; const bucket = gcs.bucket(fileBucket) const tempFilePath = `/posts/${fileName}` return bucket.file(filePath).download({ destination: tempFilePath }) .then(() => { console.log('image downloaded locally to',

Uploading files from Firebase Cloud Functions to Cloud Storage

妖精的绣舞 提交于 2020-07-05 10:21:14
问题 The documentation is too complex for me to understand. It shows how to download a file from Cloud Storage to Cloud Functions, manipulate the file, and then upload the new file to Cloud Storage. I just want to see the basic, minimum instructions for uploading a file from Cloud Functions to Cloud Storage. Why doesn't this work: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.storage = functions.firestore.document('Test

Uploading files from Firebase Cloud Functions to Cloud Storage

与世无争的帅哥 提交于 2020-07-05 10:18:12
问题 The documentation is too complex for me to understand. It shows how to download a file from Cloud Storage to Cloud Functions, manipulate the file, and then upload the new file to Cloud Storage. I just want to see the basic, minimum instructions for uploading a file from Cloud Functions to Cloud Storage. Why doesn't this work: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.storage = functions.firestore.document('Test

Why doesn't granting 'allAuthenticatedUsers' member the 'Cloud Functions Invoker' role work for google cloud functions?

早过忘川 提交于 2020-07-03 17:35:08
问题 According to the Google documentation, The 'allAuthenticatedUsers' member would include anybody that is authenticated included regular gmail accounts. So I gave that member the 'Cloud Functions Invoker' role, thinking that any authenticated user should be able to invoke my google cloud function. That is not working. I get the following results: Error: Forbidden Your client does not have permission to get URL /function-1 from this server. I have proven that if I grant the 'Cloud Functions