GCP 函数实现 HTTP 调用

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

我正在尝试从另一个 GCP 函数 (A) 调用 GCP 函数 (B)。

到目前为止,我已经:

  • 创建服务帐户并授予函数调用者角色
  • 将服务帐户添加到功能 B 作为功能管理员
  • 为创建的服务帐户下载 json 密钥
  • 尝试在本地运行代码

从 google.oauth2 导入 service_account 从 google.auth.transport.requests 导入 AuthorizedSession

function_url = 'https://europe-west6-xxx.cloudfunctions.net/yyy'
json_path = "/Users/xxx44b1.json"

credentials = service_account.IDTokenCredentials.from_service_account_file( 
         json_path, 
         target_audience=function_url,
 ) 

authed_session = AuthorizedSession(credentials)
response = authed_session.post(function_url)


response.text

但是,它不起作用,并返回:

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Page not found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Page not found</h1>
<h2>The requested URL was not found on this server.</h2>
<h2></h2>
</body></html>

我该如何解决这个问题?

python google-cloud-platform google-cloud-functions
1个回答
0
投票

您可能需要检查您的入口设置基于文档,如下所示:

  gcloud functions deploy FUNCTION_NAME 
  --trigger-http 
  --ingress-settings INGRESS_SETTINGS 
© www.soinside.com 2019 - 2024. All rights reserved.