This question already has an answer here:
How to run query from inside of Cloud function?
(1 answer)
Closed 5 years ago.
I want to create a cloud function triggered by a storage trigger which writes data into a firebase database. It seems that only during a database trigger can the cloud function talk to the firebase database.
So I want to know does anyone have an example for that or tell me if it is possible for a Google Cloud function to do it?
Thanks.
Cloud Functions can be triggered from uploads to Cloud Storage, or through writes to the Firebase Realtime Database. The samples repo on Github has examples for both.
Related
I'm trying to update my function from cloud function 1st generation (java 11) to 2nd generation. Apparently some changes imply that the old implementation of the functions through Cloud CLI doesn't work on the new cloud functions. The old trigger was setting by this command:
--trigger-event providers/google.firebase.database/eventTypes/ref.create \
--trigger-resource projects/_/instances/root/message/{message_id}
Is still possible to run a function on "OnCreate" trigger from firebase database? It looks like it could be reach with the EventArc, but I don't find anywhere how to do that. Someone is already doing that or can clarify this?
As per the comment of #DazWilkin, there's an existing public issue tracker for this issue. As per the contents of the issue (as of March 18, 2022): "Cloud functions team identified the issue: the flag doesn't support the event because it only supports PubSub and GCS events, the team is going to change the message to be more specific."
On this note, there's a preview limitation stated in the official Firebase documentation (as of March 29, 2022):
Cloud Functions (2nd gen) offers Pub/Sub, Cloud Storage and Audit Log events through Eventarc. Additional events for Firestore, Firebase RTDB, Analytics, and Auth are planned.
I'm using Firebase for my mobile app's entire backend and I was wondering which of the two is a more reliable way of performing the task of creating a user and then a batch of documents.
Create the Firebase user (using Firebase Auth) on the client and if it succeeds then perform a Firestore batch write also on the client to create the documents.
Call a Firebase cloud function from the client to perform the above task.
My reliability concern has to do with the network. If the user is created on the client but is unable to create the documents then, well, that's not good. But if the client is able to invoke a cloud function then I feel like network reliability is not an issue in the cloud environment. If the task is to fail in the cloud it will be because of violating an error that I have control over (i.e. bad email format, weak password). Which of the two is more reliable for my purposes?
If the user has a spotty connection, the call to the Cloud Functions is just as likely to fail as the call that writes them directly to Firestore. The main difference is that the Firestore SDKs will automatically retry the write operation in such cases, while with a Cloud Function you'd have to implement that yourself.
I definitely would recommend using option 1. You should create a user with Firebase Auth and then create a collection called "users" and add a document with the user's UID, which is auto generated. This should occur after you insure that there is no error in the Firebase Auth process. If there is you should just display the error. If you need more specific info, feel free to respond.
I am searching for preventing attacks like Ddos, I am not sure I came across a solution.
Case 1
in which from every request putting a increment value in firestore database. After certain value such as 100000 a cloud function will trigger which will destroy / deactivate all my cloud functions.
Case 2
Is there any easy way using if else in cloud functions.
I am new to Firebase cloud functions
I am writing cloud functions in dart
Is there any way to write security rules for calling function
Is there any way to limit invocations
Can cdn or another service integration help in this situation. I dnt want surprise bill
First of, see this documentation on the guidelines you should follow to avoid security attacks in Firebase.
in which from every request putting a increment value in firestore database. After certain value such as 100000 a cloud function will trigger which will destroy / deactivate all my cloud functions.
Unfortunately, this is not how a managed service works. Cloud Functions can only be triggered when invoked or during a response to an event. If there's no traffic, then the function is not running. It's not possible to deactivate them.
You can however, list all you functions and delete them one-by-one by using Cloud Functions Client Library and method deleteFunction().
Is there any easy way using if else in cloud functions.
For this question, are you referring to conditional statements or on how a traffic is redirected?
I am new to Firebase cloud functions I am writing cloud functions in dart
Currently, there is no official way to deploy a function running in Dart Runtime, though there are community supported projects that allow you to run Dart functions on other environments.
Node is the only runtime being supported in Cloud Function for Firebase as of the moment. See documentation here.
Is there any way to write security rules for calling function
Firebase security rules are for Cloud Firestore, Realtime Database, and Cloud Storage. See this SO that shows how to protect HTTP functions using auth id tokens and database rules.
Additionally, in this documentation, you can find how to setup security rules in your Firebase project. Sample scripts can be found here.
Is there any way to limit invocations
You can find a similar SO question here on limiting invocations in Firebase Cloud Functions. Additional details regarding Quotas and Limits can be found here.
Can cdn or another service integration help in this situation. I dnt want surprise bill
CDNs can help you bring down costs due to caching behavior, however it is not the complete solution to avoid surprise bills. One way to avoid this is to setup budget alerts to send email notifications whenever your project exceeds (or about to exceed) the set spend threshold. See documentation on Avoiding surprise bills here.
I got an iOS app and I'm storing values in Firebase per user.
Every 24 hours I need to reset those values in Firebase automatically, even when the user does not open the app.
Is it possible to do this in the app itself or do I need to write cloud code?
You can´t run this type of code when your application is not active. If you need to reset the data every 24 hours even when the user does not open the app it´s better to create a job in your backend to execute this type of action and separate this logic from the application.
An example of a job in your backend can be Cloud Functions for Firebase, since you´re already using Firebase.
Cloud Functions for Firebase lets you automatically run backend code
in response to events triggered by Firebase features and HTTPS
requests. Your code is stored in Google's cloud and runs in a managed
environment. There's no need to manage and scale your own servers.
Yes there is a way to do so. Firebase gives a cloud function support where you can write and read data whenever you want. just need to run the code ones with what type of data you want to update and then set a timer of 24 hours to change the existing data. Then you are ready to go.Here is the link of Firebase Docs for cloud functions. Go through it for more deeper understanding
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features
and HTTPS requests. Your code is stored in Google's cloud and runs in
a managed environment. There's no need to manage and scale your own
servers.
Typical use cases might fall into these areas:
Notify users when something interesting happens.
Perform Realtime Database sanitization and maintenance.
Execute intensive tasks in the cloud instead of in your app.
Integrate with third-party services and APIs.
Check this Use case:
What Can I Do with Cloud Functions: Use case
I am a fairly new developer, and right now I am developing an app where I am using the DynamoDB database to collect user account info, then acquire it to verify during a login. However, I'm having trouble because all the instructions detailing how to deploy data to DynamoDB are written for iOS developers using Objective-C. I do not know Objective-C and am having a hard time trying to figure out what it means. Also, for those familiar with DynamoDB, do I have to use Amazon Cognito when uploading to DynamoDB?
The DynamoDB Object Mapper is a ORM layer that lets you use DynamoDB as a back-end for storing your data.
It seems like this is an example of how to use DynamoDB mapper with swift.