skip to Main Content

How to set options {memory: "1GiB"} on firestore triggered cloud function.

I can’t find it in the documentation: https://firebase.google.com/docs/functions/2nd-gen-upgrade

There is an exemple for https functions but it seem to have a different syntaxe for onDocumentCreated(), etc..

export const statisticsDataCreated = onDocumentCreated("statistics/data", async (event) => {
  /** Do things **/
});

Did you find the way to achieve it ?

2

Answers


  1. As far I can see in docs here (https://firebase.google.com/docs/functions/manage-functions?gen=2nd&hl=it#set_timeout_and_memory_allocation)

    the options can be passed as the first argument before the callback function itself:

    exports.convertLargeFile = onObjectFinalized({
      timeoutSeconds: 300,
      memory: "1GiB",
    }, (event) => {
      // Do some complicated things that take a lot of memory and time
    });
    

    While there is not a specific example on the onDocumentCreated trigger, I would suggest you to use it like this:

    export const statisticsDataCreated = onDocumentCreated({memory: "1GiB"}, "statistics/data", async (event) => {
      /** Do things **/
    });
    
    Login or Signup to reply.
  2. you can use runWith to set runtime options

        export const statisticsDataCreated = functions.runWith({ memory: '1GiB', timeoutSeconds: 120 }).firestore.document("statistics/data").onCreate(async (snapshot, context) => {
        /** Do things **/
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search