To begin with rate limiting, enable it from the dashboard.
This will provide you with a new tab, and an API key. Click Rate Limiting on the navigation bar, and take a copy of your API key - you'll need this to configure your functions:
Install rate limiting package in your application¶
Currently rate limiting is only supported for nodejs firebase function applications. Please get in touch if you'd like to use python
To get started, install the flamesshield SDK into your application
npm install flamesshield-sdk --save
Then, import the package:
import{rateLimit}from"flamesshield-sdk";
Then wrap your existing function in a rateLimit:
exportconsthelloWorld=onRequest((request,response)=>{returnRateLimit({app:admin.app(),maxCalls:5,apiKey:"<APIKEY>",periodSeconds:60,onSuccess:()=>{logger.info("Hello logs!",{structuredData:true});response.send("Hello from Firebase!");},onFailure:()=>{logger.error("Rate limit exceeded!",{structuredData:true});response.status(429).send("Rate limit exceeded!");}})});
Now, you have a basic rate limiting function setup. Make sure that the name matches the function name - e.g. helloWorld matches the export helloWorld.
In the left-hand navigation menu, click on Rate Limiting.
This page displays cards for each detected Cloud Function eligible for rate limiting. Functions without a configured limit will show a Not Configured status tag.
2. Set Requests Per Second (RPS): * Locate the card for the function you wish to rate limit (e.g., ext-notification-centre-newNotificationTrigger). * In the Requests per second input field on the function's card, enter the desired maximum RPS value. In the video, the user enters 5. 3. Enable Configuration: * Click the + Enable Rate Limiting button on the same card. 4. Confirm Configuration:
The card will update:
The status tag changes to Configured (Not active).
The input field is replaced with text indicating the activation threshold (e.g., Activate at: 5 rps).
Two new buttons appear: Manually Start Rate Limiting and Configure Rate Limiting.
Find the card for the function that is currently Active.
Stop Limiting:
Click the Stop Rate Limiting button.
Confirm Deactivation:
The card will revert to the Configured (Not active) state, displaying the activation threshold and the Manually Start Rate Limiting and Configure Rate Limiting buttons again.