我正在尝试从云函数向部署在默认GAE服务上的几个应用程序引擎端点发送请求。我的代码非常简单:
import logging
import requests
def main(event, context):
bucketname = event['bucket']
filename = event['name']
endpoint = # Some logic extracting the endpoint to be used
url = 'https://myproject.ew.r.appspot.com/{}'.format(endpoint)
data = {
'bucketname': bucketname,
'filename': filename
}
r = requests.post(url, json=data)
logging.info(r)
return str(r)
云功能的部署包括:
gcloud functions deploy storage_to_gae --runtime python37 --trigger-resource $BUCKETNAME --trigger-event google.storage.object.finalize --region $REGION --source gcf/ --entry-point main --service-account cf-sa@myproject.iam.gserviceaccount.com
功能使用的服务帐户已授予服务帐户用户(roles/iam.serviceAccountUser
)角色
runtime: python37
service: default
但是,由于GAE服务上未显示任何日志,因此请求不会到达应用程序引擎。请求返回一个<Response [401]>
错误代码,因此CF似乎无法访问应用程序引擎服务
我还需要哪些角色来提供我的cf-sa@myproject.iam.gserviceaccount.com
服务帐户?我正在客户端环境上部署,因此权限有限,必须询问所需的确切角色
在询问我客户的GCP团队后,他们使用IAP管理访问
我遵循了this文档的说明,能够向GAE端点发送请求
这是我的最终代码:
相关问题 更多 >
编程相关推荐