HTTP 目标的 GCP Cloud Scheduler 错误,状态为 INTERNAL

问题描述 投票:0回答:2

我有一个调度程序作业,每 8 小时调用一次我的函数。该函数工作正常,每次当成员是角色 Roles/cloudfunctions.invoker 的“allUsers”时,都会返回 HTTP 200 状态。但是,当我通过 serviceAccount:${google_service_account.ServiceAccount.email} 使用我的服务帐户作为成员时,会出现此错误:

{
   insertId: "---"
     jsonPayload: {
       status: "INTERNAL"
       @type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
       targetType: "HTTP"
       jobName: "projects/projectname/locations/asia-northeast1/jobs/Function_Name"
       url: "https://asia-northeast1-projectname.cloudfunctions.net/Function_Name"
}
httpRequest: {
   status: 500
}
resource: {
  type: "cloud_scheduler_job"
  labels: {
     project_id: "projectname"
     job_id: "Function_Name"
     location: "asia-northeast1"
  }
}
timestamp: "2021-05-24T08:14:39.131999796Z"
severity: "ERROR"
logName: "projects/projectname/logs/cloudscheduler.googleapis.com%2Fexecutions"
receiveTimestamp: "2021-05-24T08:14:39.131999796Z"
}

并且调度程序结果为“失败”而不是“成功”。

如何修复此错误?我用于 Google Cloud Platform 的 terraform 版本是 2.20.3。代码如下所示:

resource "google_cloud_scheduler_job" "test" {
  name             = "Function_Name_Schedule_Job"
  description      = "Triggers ${google_cloudfunctions_function.Function_Name.name} function every 8 hours."
  time_zone        = "Asia/Singapore"
  schedule         =  "59 7,15,23 * * *"
  region           = "${var.Region}"
  retry_config {
    retry_count        = 5
    max_retry_duration = "520s"
  }
  http_target  {
    uri                     = "${google_cloudfunctions_function.Function_Name.https_trigger_url}"
    oidc_token {
      service_account_email = "${google_service_account.ServiceAccount.email}"
    }
  }
  depends_on = ["google_cloudfunctions_function.Function_Name"]
}
google-cloud-platform terraform terraform-provider-gcp google-cloud-scheduler
2个回答
1
投票

您需要在

oidc_token
定义中添加受众。等于您的 Cloud FUnctions URL(没有任何其他路径或参数)

    oidc_token {
      service_account_email = "${google_service_account.ServiceAccount.email}"
      audience = "${google_cloudfunctions_function.Function_Name.https_trigger_url}"
    }


0
投票

法提赫旅行社 旅行社

© www.soinside.com 2019 - 2024. All rights reserved.