My handler named taskToFireOff has allUsers
deleted, the Cloud Tasks Enqueuer
principal's name is set to the ServiceAccountEmail
, and its role is set to Invoker
(not shown)
When a post is created, I use .onCreate
to create a task. The task is created but the function that the http request is connected to never fires. I looked here
But when I created my Storage bucket, I selected us-east1
. At the bottom of Firestore Database it says
When I enter $ gcloud app describe
it says that the locationId is us-east1
Could the problem be that the Cloud Task is in us-east1
but the Cloud Functions are in us-central1
?
Running $ gcloud functions list
lists all of my Cloud Functions in the us-central1
region
Btw, I created another project just to see the selection that I'm given when creating a Storage bucket. For Storage, there isn't a way to select us-central1. There is a default Multi-region nam5(us-central
) but there isn't a specific region for us-central1
. I selected us-east1
because I'm in NY.
CodePudding user response:
The problem was that the App Engine was in us-east1
but the function handler taskToFireOff was in us-central1
. The error was saying that the function associated with App Engine/Cloud Task needs to be in the same region together. In short I needed to change that particular cloud function’s region.
To fix the issue I had to create a new handler which was pretty easy. I followed this answer which led me to this link specifically the Change a function's region or regions section.
1st- in terminal I ran:
$ gcloud app describe
// use whatever appears for the locationId which for me was us-east1
2nd- I added this new function to the index.js file:
// whatever appeared for the locationId I put inside the region param
exports.newTaskToFireOff = functions.region('us-east1').https.onRequest((request, response) => {
// ... in here I c p all of the code from my initial taskToFireOff function
});
3rd- I ran this in terminal to update gcloud with the new function
$ firebase deploy --only functions:newTaskToFireOff
4th- I ran this in terminal to delete the old function from gcloud:
$ firebase functions: delete taskToFireOff
5th- I went into my index.js file and manually deleted the entire taskToFireOff. You won't need the old function, just the code from inside of it
// I deleted this old function
exports.taskToFireOff = functions.https.onRequest((request, response) => {
// ... I took this code and c p inside the newTaskToFireOff before I deleted this function
});
7th-
When I go to the console's Cloud Functions page the old taskToFireOff is no longer there and the newTaskToFireOff is there with the region us-east1
After you finish these steps don’t forget that the new function from step 2 you have to go to the Cloud console (use the above link) and change its Permissions
. Set the role to Invoker
and set its principal role name to use whatever you set for the Cloud Task's ServiceAccountEmail
otherwise it still won’t work. You should delete allUsers
too.