-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to pass parameterized config value to functions.storage.bucket(<param>).object().onFinalize #1413
Comments
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? |
Came across the same problem. |
Hi |
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! |
@taeold any update on this feature? |
I am also looking for this feature. It seems very important for managing buckets in multiple environment. |
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 |
Still biting developers in the butt. Good grief. Please update your documentation. |
Have you provided any solution so far? Hard coding the target buckets is a terrible approach when dealing with multiple projects. |
Here goes a workaround while Google doesn't come up with something. src/environment.ts: export const setupEnvironmentVariables = () => {
console.log("Using project:", process.env.GCLOUD_PROJECT);
// Firebase Functions Emulator currently not loading .env files properly:
// https://github.com/firebase/firebase-functions/issues/1094
// Also a workaround for deploying when trigger fun parameters depend on environment:
// https://github.com/firebase/firebase-functions/issues/1413
switch (process.env.GCLOUD_PROJECT) {
case 'project-1-id':
dotenv.config({ path: `${__dirname}/../.env.project-1-env-file` });
break;
case 'project-2-id':
dotenv.config({ path: `${__dirname}/../.env.project-2-env-file` });
break;
.
.
.
default: // Used by other devs on my team with their own projects
dotenv.config({ path: `${__dirname}/../.env.emu` });
}
}; src/index.ts import { setupEnvironmentVariables } from './environment';
// At the very beginning of your entry point.
setupEnvironmentVariables(); path/to/your/triggers.ts: // Some env-dependant trigger:
export const onEnvDependantTrigger = functions
.storage.bucket(process.env.MY_TARGET_BUCKET) // defined on each of your .env files |
You can also use v2 triggers and there the bucket name can be used as a parameter: import { defineString } from "firebase-functions/params"
import { onObjectFinalized, StorageObjectData } from "firebase-functions/v2/storage"
const pdf_bucket_name = defineString('PDF_BUCKET_NAME')
export const onLeafletPdfFileUpload = onObjectFinalized({ bucket: pdf_bucket_name }, async (event) => {
await handlePdfUpload(event.data)
}) |
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:
[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
The text was updated successfully, but these errors were encountered: