firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.02k stars 201 forks source link

Unable to pass parameterized config value to functions.storage.bucket(<param>).object().onFinalize #1413

Open indicava opened 1 year ago

indicava commented 1 year ago

Related issues

[REQUIRED] Version info

node: v16.19.1

firebase-functions: 4.4.0

firebase-tools: 12.3.0

firebase-admin: 11.9.0

[REQUIRED] Test case

create an .env file with these contents:

DEFAULT_STORAGEBUCKET=img.mydomain.com

Then create an index.js file with this function definition:


import functions from "firebase-functions"
import { defineString } from "firebase-functions/params"
const defaultBucket = defineString("DEFAULT_STORAGEBUCKET")

export const resizeImages = functions.storage.bucket(defaultBucket).object().onFinalize(async (object) => {
functions.logger.info(`defaultBucket.value() = ${defaultBucket.value()}`)
})

[REQUIRED] Steps to reproduce

run "firebase emulators:start" or "firebase deploy"

[REQUIRED] Expected behavior

Expected behavior is Storage triggered cloud function for the bucket named "img.mydomain.com"

[REQUIRED] Actual behavior

Actual behavior is I am getting this error message:

functions: Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: Error: Invalid bucket name params.DEFAULT_STORAGEBUCKET

Were you able to successfully deploy your functions?

No I was unable to deploy

taeold commented 1 year ago

Hi @indicava. Thanks for raising the issue.

We don't support parametrizing storage buckets using params yet. Params only work on configuration options like timeouts and memory for now. Sorry for the confusion!

indicava commented 1 year ago

Hi @indicava. Thanks for raising the issue.

We don't support parametrizing storage buckets using params yet. Params only work on configuration options like timeouts and memory for now. Sorry for the confusion!

Thanks for the update.

So do you have any suggestion on how to approach this issue when I am managing several environments with different bucket names using the same codebase?

zallesov commented 1 year ago

Came across the same problem. I do not see a solution here. How could I subscribe to different buckets for dev and prd environments? There seem to be no way to provide deployment time params?

raf-a commented 1 year ago

Hi I encountered the same problem. I found a solution using the environment variable process.env.GCLOUD_PROJECT.

indicava commented 1 year ago

Hi

I encountered the same problem. I found a solution using the environment variable process.env.GCLOUD_PROJECT.

Hi,

Could you elaborate a little more on how you use that environment variable to parameterize bucket names?

Maybe post/link some sample code?

Thanks!

markglibres commented 1 year ago

@taeold any update on this feature?

amankr commented 1 year ago

I am also looking for this feature. It seems very important for managing buckets in multiple environment. currently I have to change names manually while deploying to different environments, which is very inconvenient. I hope this is picked up soon . issue also mentioned here -> https://github.com/firebase/firebase-functions/issues/1369

nickesk commented 9 months ago

This is a bug IMO. We cannot use firebase function params as the documentation instructs us to if these basic top-level methods don't work with Params, and there is no published workaround. Will the Firebase team please prioritize this?

otri commented 1 month ago

Still biting developers in the butt. Good grief. Please update your documentation.