4
votes

How can I deploy a scheduled function to Google Firebase Functions?

I have created a Service Account named

cron-notifications

My code for the function

exports.notification_email = functions
.region('europe-west1')
.pubsub
.schedule('0 * * * *')
.timeZone('Europe/Stockholm')
.onRun(async (event) => { ... }

When I try to deploy using

$ firebase deploy --only functions:notification_email 

I get the error below.

Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1

I can deploy other functions that are not scheduled to "europe-west1" . I think my project is in europe-west1 (how can I verify?)

I have also tried creating a function named notification_email, located in europe-west1, directly from the GCP Cloud Functions Web UI and then deploying my function - overwriting it - with the same result.

I also tried setting the region using

gcloud config set functions/region europe-west1

as stated in the documentation, with the same result.

My $ gclod config list

[core]
account = myAccount
disable_usage_reporting = True
project = myProject
[functions]
region = europe-west1

Please help me out here! :)

1
which version of the cli are u using? - andresmijares
Hi @andresmijares! I am using version 7.2.2 of the Firebase CLI. - Kermit
I had a similar issue a few months ago, I had to downgrade my CLI to 7.2.0, maybe it could work for you - andresmijares
Hi @andresmijares ! I did not try a downgrade, but upgraded to 7.4.4 and am having the same issue. Google has indicated the issue might origin from the publishing of the scheduler function. I will update the post when I have more information. - Kermit

1 Answers

1
votes

When you are using scheduled functions in Firebase Functions, an App Engine instance is created that is needed for Cloud Scheduler to work. You can read about it here.

When those resources are launched for the scheduler to work, they use the location that has been set by default for resources.

Cloud Functions for Firebase (scheduled functions only) — If you run scheduled functions, Cloud Scheduler requires a Google App Engine app; during its setup you're prompted to select your project's default Google Cloud Platform (GCP) resource location (if it wasn't already selected when setting up another service).

I think that you are getting that error because there is a difference between the default GCP resource location you specified and the function one.

More background:

Important: Cloud Scheduler requires that your project have a Google App Engine (GAE) app; during its setup you're prompted to select your project's default Google Cloud Platform (GCP) resource location. This location will be used for GCP services in your project that require a location setting, specifically, your default Cloud Storage bucket and your Cloud Firestore database. When setting your project's default GCP resource location, primarily consider where you want to store your data and files and, secondly, where you want to run any triggered functions for Cloud Firestore and Cloud Storage. After you set your project's default GCP resource location, you cannot change it.

Link

If you click on the cogwheel next to project-overview in Firebase you can see where your resources are located.

Hope this helps.