首页 > 解决方案 > 使用 Cloudrun 为 ENDPOINTS_SERVICE_NAME 环境变量接收 Google Cloud Endpoints 错误

问题描述

使用 ESPv2 Beta sidecar 容器设置后端服务后收到以下错误消息。

Serverless ESPv2 expects ENDPOINTS_SERVICE_NAME in environment variables.

 Did you forget to build the Endpoints service configuration
 into the ESPv2 image? Please refer to the official serverless
 quickstart tutorials (below) for more information.

 https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-run#configure_esp
 https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-functions#configure_esp

 If you are following along with these tutorials but have not
 reached the step above yet, this error is expected. Feel free
 to temporarily disregard this error message.

 If you wish to skip this step, please specify the name of the
 service in the ENDPOINTS_SERVICE_NAME environment variable.
 Note this deployment mode is **not** officially supported.
 It is recommended that you follow the tutorials linked above.

看起来我能够正确设置云运行服务,能够直接从 API 获取响应。

审查gcloud_build_image它似乎没有变量。

https://github.com/GoogleCloudPlatform/esp-v2/blob/9a5a03d439867b0d5563081ac574e94d51922c32/docker/serverless/gcloud_build_image#L53

标签: google-cloud-platformgoogle-cloud-rungoogle-cloud-endpoints-v2

解决方案


像这样更新部署 Cloud Endpoint 的 Cloud Run 环境变量

gcloud beta run services update <SERVICE NAME> \
--set-env-vars ENDPOINTS_SERVICE_NAME=<SERVICE NAME>-<hash>-<REGION>.a.run.app \
--region <REGION> --platform managed

更多细节在我的文章中


推荐阅读