为了账号安全,请及时绑定邮箱和手机立即绑定

使用 go 客户端部署 GCP 云功能时,我收到:“错误 400:前提条件检查失败。

使用 go 客户端部署 GCP 云功能时,我收到:“错误 400:前提条件检查失败。

Go
慕桂英546537 2022-05-23 15:29:21
我正在尝试使用谷歌的 go 客户端包部署谷歌云功能。(https://pkg.go.dev/google.golang.org/api/cloudfunctions/v1?tab=doc#pkg-overview)我将其分解为我认为最相关的片段:import (    "context"    log "github.com/sirupsen/logrus"    functions "google.golang.org/api/cloudfunctions/v1")func main() {    ctx := context.Background()    CloudFunctionService, err := functions.NewService(ctx)    if err != nil {        log.Printf("Error at functions.NewService(ctx): \"%v\"\n", err)    }    FunctionSpec := functions.CloudFunction{            EntryPoint:        "DeployThisFunctionEntryPoint",            EventTrigger: &functions.EventTrigger{                EventType: "google.pubsub.topic.publish",                Resource:  "projects/mytestproject/topics/cloud-builds",            },            Name:                "DeployThisFunction",            Runtime:             "go111",            SourceRepository:    &functions.SourceRepository{Url: "https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//"},    }    CloudFunctionDeploymentService := functions.NewProjectsLocationsFunctionsService(CloudFunctionService)    createCall := CloudFunctionDeploymentService.Create("projects/mytestproject/locations/us-central1", &FunctionSpec)    resp, err := createCall.Context(ctx).Do()    if err != nil {        log.Printf("Error at createCall.Context(ctx).Do(): \"%v\"\n", err)    }    log.Printf("response createCall.Context(ctx).Do(): \"%v\"\n", resp)}但是,无论我如何格式化它或尝试。我总是收到以下消息:googleapi: Error 400: Precondition check failed., failedPrecondition 通过google api explorer,我使用他们的身份验证和json方案运行了请求,我收到了同样的错误。https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/create回复:{  "error": {    "code": 400,    "message": "Precondition check failed.",    "status": "FAILED_PRECONDITION"  }}我无法弄清楚出了什么问题。我已经开始了自己的项目并且是管理员。当使用 GCP 运行 go 客户端的另一部分时,例如创建存储、IAM 用户、服务帐户、数据库,我可以使其工作并创建这些资源。如果有人遇到此问题,我将不胜感激。
查看完整描述

1 回答

?
阿波罗的战车

TA贡献1862条经验 获得超6个赞

eventType应该匹配模式: providers/*/eventTypes/*.*.

例如:providers/cloud.pubsub/eventTypes/topic.publish

SourceRepository url 也应该是https://source.developers.google.com/projects/*/repos/*/revisions/*/paths/ ,你有https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//

错误消息说这是您配置方式的问题FunctionSpec,我怀疑EventTriggerSourceRepository字段。

编辑

code: 400是一个错误的请求,客户端错误,在这种情况下是格式问题,首先要检查的是每个云函数文件


查看完整回答
反对 回复 2022-05-23
  • 1 回答
  • 0 关注
  • 317 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号