【问题标题】:I'm not sure if this is Cloud Pub/Sub internal error我不确定这是否是 Cloud Pub/Sub 内部错误
【发布时间】:2019-08-12 11:35:45
【问题描述】:

最近我在测试我的 Google Cloud 功能时开始收到此错误:

textPayload:  "2019/08/12 11:15:58 error publishing to the topic - rpc error: code = Unauthenticated desc = transport: compute: Received 500 `Could not fetch URI /computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpubsub"

这让我很惊讶。最近我对功能进行了一些更改,但似乎并非如此。我恢复到以前工作的旧代码,我得到了同样的错误。

我读到Cloud Pub/Sub docs on errors

INTERNAL 500 此错误表示内部服务器错误;它不应该发生。如果出现此错误,请向云支持报告。错误应该是暂时的。

我已将其报告给云支持。

不过,我不确定这是 Google Cloud 内部错误还是由我的代码引起的错误。

编辑:这是 Go 中的极简代码。

package testfcn

import (
    "log"
    "net/http"

    "cloud.google.com/go/pubsub"
)

func TestFcn(w http.ResponseWriter, r *http.Request) {

    ctx := r.Context()

    client, err := pubsub.NewClient(ctx, "min-fotball-staging")
    if err != nil {
        log.Print("error creating PubSub client - ", err)
        return
    }

    topic := client.Topic("TestTopic")

    result := topic.Publish(ctx, &pubsub.Message{
        Data: []byte("TestMessage"),
    })

    _, err = result.Get(ctx)
    if err != nil {
        log.Print("error publishing to the topic - ", err)
        return
    }

}

我有一个名为 TestTopic 的主题。

【问题讨论】:

  • 制作一个小项目/伪代码来复制问题。将帮助您在这里得到一些答案。
  • @NarendranPandian 我成功了。
  • 我无法复制相同的错误消息。根据该错误,您的函数似乎在检索服务帐户令牌时遇到问题。您使用什么服务帐户进行身份验证?它是否存在,是否具有发布所需的权限?
  • @Lauren 就是这样。它真的看起来像 GCP 错误。我们尝试使用具有 Owner 角色的默认帐户和仅具有 Pub/Sub Publisher 角色的专用服务帐户。
  • 谢谢。 stackoverflow.com/questions/56312091/… 看起来可能是相关的,你能看看这个问题是否解决了你的问题吗?如果没有,您能否提供有关您的 Cloud Function 设置的更多信息,以便我们可以复制此错误?您使用的是哪种 Cloud Function 触发器?您是否从默认值更改了任何功能设置?另外,关于您的 Go 设置:您使用的是什么 Go 版本以及您的 go.mod 中有什么?

标签: google-cloud-platform google-cloud-functions google-cloud-pubsub


【解决方案1】:

这不是 Cloud Pub/Sub 客户端库的内部错误。

项目的service-<project_number>@gcf-admin-robot.iam.gserviceaccount.com 服务帐户尚未分配Cloud Functions Service Agent 角色。

无法通过 Google Cloud Console 添加此角色,而是使用gcloud 命令:

gcloud projects add-iam-policy-binding <project_name> --role=roles/cloudfunctions.serviceAgent --member=serviceAccount:service-<project_number>@gcf-admin-robot.iam.gserviceaccount.com

可能有用的链接:

额外: 就我而言,此服务帐户具有 Owner 角色。这意味着Owner 角色没有Cloud Functions Service Agent 角色拥有的某些权限。

【讨论】:

    猜你喜欢
    • 2021-12-12
    • 2017-09-28
    • 2022-01-13
    • 2019-07-26
    • 1970-01-01
    • 2020-04-03
    • 2021-12-28
    • 2015-05-21
    • 1970-01-01
    相关资源
    最近更新 更多