Posts

Showing posts with the label Google Cloud Functions

Cloud Function To Export Firestore Backup Data. Using Firebase-admin Or @google-cloud/firestore?

Answer : The way you're accessing the admin client is correct as far as I can tell. const client = new admin.firestore.v1.FirestoreAdminClient({}); However, you probably won't get any TypeScript/intellisense help beyond this point since the Firestore library does not actually define detailed typings for v1 RPCs. Notice how they are declared with any types: https://github.com/googleapis/nodejs-firestore/blob/425bf3d3f5ecab66fcecf5373e8dd03b73bb46ad/types/firestore.d.ts#L1354-L1364 Here is an implementation I'm using that allows you to do whatever operations you need to do, based on the template provided by firebase here https://firebase.google.com/docs/firestore/solutions/schedule-export In my case I'm filtering out collections from firestore I don't want the scheduler to automatically backup const { Firestore } = require('@google-cloud/firestore') const firestore = new Firestore() const client = new Firestore.v1.FirestoreAdminClient() const bu...

Cloud Functions For Firebase Killed Due To Memory Limit Exceeded

Answer : You can set this from within your Cloud Function file on Firebase. const runtimeOpts = { timeoutSeconds: 300, memory: '1GB' } exports.myStorageFunction = functions .runWith(runtimeOpts) .storage .object() .onFinalize((object) = > { // do some complicated things that take a lot of memory and time }); Take from the docs here: https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation Don't forget to then run firebase deploy from your terminal. I was lost in the UI, couldn't find any option to change the memory, but finally found it: Go to the Google Cloud Platform Console (not the Firebase console) Select Cloud Functions in the menu Now you see your firebase function in here if it's correct. Otherwise check if you selected the right project. Ignore all checkboxes, buttons and menu items, just click on the name of the function . Click on edit (top menu) and only change the allocated me...

Can You Call Out To FFMPEG In A Firebase Cloud Function

Answer : ffmpeg is not preinstalled (pretty much just ImageMagick); to see exactly what's installed check out the Dockerfile here: https://github.com/GoogleCloudPlatform/nodejs-docker/blob/master/runtime-image/Dockerfile. However, you can upload arbitrary binaries when you upload your code using gcloud beta functions deploy because everything in the current directory (except node_modules ) is uploaded. Note: you only have disk write access at /tmp/ . Option 1: use ffmpeg-static npm module ffmpeg-static is an npm module that builds the correct ffmpeg binary based on the current system during npm install . Since Cloud Functions builds your code in the cloud, it'll build the correct ffmpeg binary. https://github.com/eugeneware/ffmpeg-static You can see it in action in the Cloud Functions for Firebase examples repo. const ffmpeg = require('fluent-ffmpeg'); const ffmpeg_static = require('ffmpeg-static'); var cmd = ffmpeg('/tmp/video.avi') ....