update Firebase emulator function timeout duration - firebase

When emulating firebase functions locally is there a way to change the function timeout from the default 60s?
--idlePruneInterval has been added as an option to the google cloud emulator CLI: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/66
This option doesn't appear to work is not officially supported in either the firebase serve mode:
firebase serve --only functions --idlePruneInterval=5000
or the experimental shell emulation:
firebase experimental:functions:shell --idlePruneInterval=5000
Is there another way around this problem? Perhaps editing a config file?

The Cloud Functions emulator from Firebase is separate from the one provided by the Google Cloud Platform org. The command line parameters from one won't necessarily work on the other.

Related

How to Firebase cloud function deploy privately

When i use firebase deploy --only functions to deploy cloud functions for firebase, i discover, that this functions are deployed with the authentication flag allUsers.
How can i deploy firebase cloud function with private by default as mentioned here ?
There is no way to set this access control level of Cloud Functions through the Firebase CLI. It currently indeed always sets the access to allow all users. It sounds like a reasonable request to allow control of this though, so I'd file a feature request and possibly a PR on the repo.
For now: if you want to set this access level, you will have to do so in the Cloud console as explained in the Google Cloud documentation on controlling access on a function.

Getting Cloud Functions url for unit testing with emulator

I have a couple of Cloud Functions that interact with Cloud Firestore. I've managed to start emulator for both (firebase emulators:start --only functions,firestore) and I run the request and it works. However, the URL for emulated functions is fairly long...
http://localhost:5001/my-app/us-central1/myFunc
I would like to either get a whole url or assemble it somehow. The my-app could be in theory read from .firebaserc where the default is specified. However, I am not sure about port or region.

Can I run Firebase Storage cloud functions locally?

From Firebase DOCS:
Run functions locally
The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types:
HTTPS functions
Callable functions
Cloud Firestore functions
You can run functions locally to test them before deploying to production.
QUESTION
Is there a way to run cloud functions for Firebase Storage (ex: triggered by file upload) locally or do I need to actually deploy them for testing?
firebaser here
Update: the Firebase Emulator Suite now also supports Cloud Storage. This includes uploads to emulated Cloud Storage triggering emulated Cloud Functions.
See the documentation for full details.
Storage has been implemented in firebase tools 9.11.0. I just took it for a test run, and I found that functions running in the emulator are, indeed, triggered by uploads to the emulated storage.
https://github.com/firebase/firebase-tools/issues/1738#issuecomment-843256335

How to setup vpc connector for firebase cloud functions?

Firebase Cloud Functions run on top of GCP, so, do they support using a vpc connector?
What I'm trying to achieve is to limit a forward-proxy server to only accept requests from the internal network, but since Cloud Functions doesn't support static IPs, the only way would be via vpc connector.
This seems now to be handled in latest firebase-tools v8.9.0 version.
Must be used in conjunction with firebase-functions v3.11.0 or higher
https://github.com/firebase/firebase-tools/releases/tag/v8.9.0
functions
.runWith({
vpcConnector: 'test-connector',
vpcConnectorEgressSettings: 'PRIVATE_RANGES_ONLY'
})
.auth.user()
.onCreate((user) => user);
Cloud Functions for Firebase doesn't actually run "on top of" GCP. Firebase just adds tools and SDKs that make Cloud Functions easier to use for some developers. The core Cloud Functions product is exactly the same, no matter if you're building and deploying with Firebase tools or gcloud.
You should still be able to configure a VPC connector for functions deployed with the Firebase CLI. You will just not able able to configure it on the command line like you can with gcloud. Instead, you will have to configure the connector in the Cloud console after deploying the function, exactly as described in the documentation you linked to.
Since Firebase is just a wrapper for Google Cloud Functions, just bypass the Firebase CLI and use the one with more parameters. (Google Cloud CLI)
i.e.
$ gcloud functions deploy <function_name> --trigger-http --runtime nodejs10 --vpc-connector projects/<your_project_name>/locations/<your-vpc-region>/connectors/<vpc_name> --service-account <your-role-name>
Source:
https://cloud.google.com/functions/docs/networking/connecting-vpc

Firebase: how to debug onCall functions?

I am using Google Cloud Functions Emulator for debugging locally my Firebase functions.
Firebase recommend to use functions.https.onCall functions instead of functions.https.onRequest for avoid using http calls directly. Instead Firebase recommend to use Firebase Functions SDK for call such functions from code.
For functions.https.onRequest I used http-trigger flag but how can I debug onCall functions ?
I found a way to run 'onCall' cloud functions locally and call them from a local client. I still haven't figured out how to attach a debugger but at least I can iterate faster and use console.log statements.
Use firebase serve to host the functions. Even though these are supposed to be for http requests I found that the the firebase clients have a property to override the host name for onCall functions. This takes care of authentication and passing in the right data and context objects for you.
From Terminal in the root of your firebase project folder:
firebase serve
You should get a successful result in the terminal window. Take the hostname and port number:
✔ functions: helloWorld: http://localhost:5000/your-project-name/us-central1/helloWorld
iOS client:
Functions.functions().useFunctionsEmulator(origin: "http://localhost:5000")
NOTE: you have to disable App Transport Security in iOS for this to work
NOTE: other clients probably have the same API.

Resources