繁体   English   中英

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

[英]When deploying GCP cloud function with go client I receive: "Error 400: Precondition check failed., failedPrecondition"

我正在尝试使用谷歌的 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 用户、服务帐户、数据库,我可以使其工作并创建这些资源。

如果有人遇到过这个问题,我将不胜感激。

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是一个错误的请求,客户端错误,在这种情况下是格式问题,首先要检查的是每个云函数文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM