typescriptfirebasegoogle-cloud-functionsfirebase-storagefirebase-tools

Firebase Cloud Function - Can't find the storage bucket region


Trying to deploy my firebase cloud function and getting the following error:

Error: Can't find the storage bucket region

enter image description here

The function I'm trying to deploy looks like:

import {initializeApp} from "firebase-admin/app";
import {getStorage} from "firebase-admin/storage";
import {getFirestore} from "firebase-admin/firestore";
import {logger} from "firebase-functions";
import {onDocumentDeleted} from "firebase-functions/v2/firestore";
import {onObjectFinalized} from "firebase-functions/v2/storage";

initializeApp();

export const onThumbUploaded = onObjectFinalized(
  {
    bucket: "<MY_PROJECT_ID>.appspot.com",
    region: "us-central1",
  },
  async (event) => {
    //... rest of my code...
  });

enter image description here

I could not find anything regarding this issue at all in google or AI-Tools.


Solution

  • Firstly, the name of your bucket in your code (ending with appspot.com) doesn't match what you show in your screenshot (ending with firebasestorage.app).

    As seen in the documentation:

    Note: Starting October 30, 2024, all new default Cloud Storage buckets have the name format PROJECT_ID.firebasestorage.app. Any default buckets created before that date have the name format PROJECT_ID.appspot.com. Learn more in the FAQs.

    If you're targeting your default storage bucket (the one created automatically for you by the Firebase console), then you shouldn't even need to use its name and region at all in your code, as they are already the default. Just leave off the configuration object entirely and provide only your handler function, which is valid usage according to the API documentation for onObjectFinalized:

    export const onThumbUploaded = onObjectFinalized(async (event) => {
        //... rest of my code...
    });
    

    If you do need a configuration object for your function, note that bucket and region properties are both optional in that object (that's what the question mark means in the type). Leaving these out should also trigger on the default bucket.