I have a Google Cloud Function that works perfectly when I test the Cloud Function from Firebase. I have set it to trigger from a Pub/Sub topic, and when I manually publish a message from the Google Pub/Sub Topic Messages form, my cloud function also correctly triggers.
However when I set up a Cloud Scheduler job, I define the schedule, using the same Region as the Pub/Sub topic, select Pub/Sub as the target type and then the proven Pub/Sub topic as the target, and create the job- and it fails every time. There is no payload to my message as it just triggers the function, so I enter "Hello there" as the message.
I have set up the App Engine default service account in the IAM settings to have all of these permissions:
Cloud Functions Admin
Cloud Scheduler Admin
Cloud Scheduler Service Agent
Editor
Firebase Admin
Firebase Realtime Database Service Agent
Pub/Sub Admin
Pub/Sub Publisher
Pub/Sub Subscriber
Service Account Token Creator
And still, I get this error in the logs:
{
insertId: "8w7lidfgug942"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
jobName: "projects/budget-app-d568a/locations/us-central1/jobs/RecurrenceButler"
pubsubTopic: "projects/budget-app-d568a/topics/firebase-schedule-checkRecurringPurchases-us-central1"
status: "UNAUTHENTICATED"
targetType: "PUB_SUB"
}
logName: "projects/budget-app-d568a/logs/cloudscheduler.googleapis.com%2Fexecutions"
receiveTimestamp: "2023-07-07T18:49:18.573174465Z"
resource: {
labels: {
job_id: "RecurrenceButler"
location: "us-central1"
project_id: "budget-app-d568a"
}
type: "cloud_scheduler_job"
}
severity: "ERROR"
timestamp: "2023-07-07T18:49:18.573174465Z"
}
I've tried re-creating the Cloud Scheduler Job, using a different service account, and nothing works. I even went through and followed the tutorial for creating a new Scheduled Job using the cron-job tutorial, and even that failed with the same error code.
In Cloud Functions, I can see that my cloud function is in a "1st gen" environment.
I have been pulling my hair out over this, what am I doing wrong? Cloud support is $500 a month and I am just a single developer, but this issue is causing a ton of problems.
Any help is greatly appreciated, thanks!