GCP Cloud Scheduler API 问题
Posted
技术标签:
【中文标题】GCP Cloud Scheduler API 问题【英文标题】:GCP Cloud Scheduler API Issues 【发布时间】:2019-08-03 07:37:20 【问题描述】:我正在尝试通过 terraform 测试设置 GCP Cloud Scheduler 作业,并在尝试通过 API 创建时发现问题。我还在此页面上测试 API:projects.locations.jobs/create。我看到的错误与无效参数有关:
"error":
"code": 400,
"message": "Job name must be formatted: \"projects/\u003cPROJECT_ID\u003e/locations/\u003cLOCATION_ID\u003e/jobs/\u003cJOB_ID\u003e\".",
"status": "INVALID_ARGUMENT"
然后我修改以适应该格式并看到此错误:
"error":
"code": 400,
"message": "Resource name should start with \"/projects/\u003cPROJECT_ID\u003e/\"",
"status": "INVALID_ARGUMENT"
请求正文如下所示:
"name": "projects/<my-project-id>/locations/us-central1/jobs/snapshots",
"pubsubTarget":
"topicName": "disk-snapshot-function-trigger",
"attributes":
"num_backups": "5",
"project": "<my-project-id>"
,
"schedule": "0 19 * * *",
"timeZone": "America/Los_Angeles"
真的没有胜算,所有请求都会得到 ERROR 400。
【问题讨论】:
terraform 是如何解决这个问题的?删除该标签。您的topicName
格式不正确projects/PROJECT_ID/topics/TOPIC_ID
@JohnHanley 感谢您的建议。通过将 project/PROEJCT_ID/topics/TOPIC_ID
前缀添加到 pubsub 主题名称中,我能够让它在 Terraform 中工作
您的回答使 terraform 标签变得有价值。谢谢。
【参考方案1】:
以这种方式正常工作:
"name": "projects/PROJECT_ID/locations/us-central1/jobs/snapshots",
"pubsubTarget":
"topicName": "projects/PROJECT_ID/topics/disk-snapshot-function-trigger",
"attributes":
"num_backups": "5",
"project": "PROJECT_ID"
,
"schedule": "0 19 * * *",
"timeZone": "America/Los_Angeles"
或使用 Terraform:
resource "google_cloud_scheduler_job" "snapshot_schedule"
provider = "google-beta"
name = "snapshots"
schedule = "$var.snapshot_schedule"
time_zone = "America/Los_Angeles"
project = "$var.project_id"
pubsub_target
topic_name = "projects/$var.project_id/topics/$google_pubsub_topic.trigger_disk_snapshot_function_pubsub.name"
data = "$base64encode("\"project\":\"$var.project_id\", \"num_backups\":\"$var.num_backups\"")"
【讨论】:
以上是关于GCP Cloud Scheduler API 问题的主要内容,如果未能解决你的问题,请参考以下文章
GCP Cloud Scheduler 为 HTTP 目标类型抛出错误
Google 部署管理器 Cloud Scheduler 类型
Cloud Endpoint 和 API Gateway (GCP) 是不是支持 Websocket?
您的应用包含公开的 Google Cloud Platform (GCP) API 密钥
了解来自 GCP 的“需要采取行动”的电子邮件,重新:启用 Cloud Build API
您的应用包含公开的 Google Cloud Platform (GCP) API 密钥。有关详细信息,请参阅此 Google 帮助中心文章