THE PROBLEM:
I am trying to deploy a simple scheduled Firebase Function like this:
import { logger } from "firebase-functions/v2";
import { onSchedule } from "firebase-functions/v2/scheduler";
export const testFunction = onSchedule("every day 00:00", () => {
logger.info("Hello world");
});
During the initial deployment I get this error:
HTTP Error: 403, The principal (user or service account) lacks IAM
permission “cloudscheduler.jobs.update” for the resource
“projects/PROJECT_ID_REDACTED/locations/us-central1/jobs/firebase-schedule-testFunction-us-central1”
(or the resource may not exist).
But strangely, even with that error, I can see in Google Console that the function has deployed successfully.
Subsequent deploys go through fine without error. In subsequent deploys it says functions[testFunction(us-central1)] Skipped (No changes detected)
because the function is deployed correctly.
Then, if I try to remove that function I get another error:
HTTP Error: 403, The principal (user or service account) lacks IAM
permission “cloudscheduler.jobs.delete” for the resource
“projects/PROJECT_ID_REDACTED/locations/us-central1/jobs/firebase-schedule-testFunction-us-central1”
(or the resource may not exist).
This time the error is correct because when I check Google Console I can see the function is not deleted.
IAM PERMISSIONS:
Obviously the fist thing I checked was the IAM Permissions.
The service account for Gen 2 function is [email protected]
which I can see on my project. I gave it the role of Cloud Scheduler Admin which includes all the required cloudscheduler.*
permissions (cloudscheduler.jobs.update
and cloudscheduler.jobs.delete
) but this has no effect. The error messages are still the same.
I am confused how to smoothly manage the deployment of Firebase scheduled functions from the Firebase CLI.