https://us-central1-poised-breaker-162819.cloudfunctions.net/function-1
但是我想以这种方式使用它或者
https://myfunction.com/thisroute
实际上这是关于命名空间甚至代理请求到适当函数的问题。如何实现呢?更新1:
看起来我们可以使用Endpoints服务来实现。但它是否能与GCF一起使用还不清楚。
https://us-central1-poised-breaker-162819.cloudfunctions.net/function-1
但是我想以这种方式使用它或者
https://myfunction.com/thisroute
实际上这是关于命名空间甚至代理请求到适当函数的问题。如何实现呢?Cloud Endpoints充当云函数的API网关。
对于云函数https://[CLOUD_FUNCTION_REGION].cloudfunctions.net/my-function,
Set project id in Cloud shell
gcloud config set project [PROJECT_ID]
Deploy ESPv2 Beta to Cloud Run. Replace CLOUD_RUN_SERVICE_NAME with the name that you want to use for the service.
gcloud run deploy CLOUD_RUN_SERVICE_NAME \
--image="gcr.io/endpoints-release/endpoints-runtime-serverless:2" \
--allow-unauthenticated \
--platform managed
At the end of command execution, it will have similar details as below
Service [CLOUD_RUN_SERVICE_NAME] revision [CLOUD_RUN_SERVICE_NAME-00001-ces] has been deployed and is serving 100 percent of traffic at https://CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app
Note host-name receive from the above command (CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app)
Create YAML file api.yaml with OpenAPI spec config:
swagger: '2.0'
info:
title: Cloud Endpoints + GCF
description: Sample API on Cloud Endpoints with a Google Cloud Functions backend
version: 1.0.0
host: CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app
schemes:
- https
produces:
- application/json
paths:
/thisroute:
get:
summary: Custom function route
x-google-backend:
address: https://[CLOUD_FUNCTION_REGION].cloudfunctions.net/my-function
responses:
'200':
description: A successful response
schema:
type: string
Deploy Endpoint configuration:
gcloud endpoints services deploy api.yaml
Now, Cloud function request can route through endpoint https://CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app/thisroute.
Also to use custom domain name, need to verifying a domain name. For that follow steps from here
operationId
条目。我并不完全理解文档,但当我在get:
部分创建一个API时,它部署了一个API。 - undefined目前不可能。您需要一个API代理,但我真的不建议公开公共URL。
在我看来,此时最优雅的解决方案是基于云发布/订阅创建简单的代理应用程序,您可以在gap、gke或新的cloud run上运行它,以便您可以扩展到0。
逻辑可以是动态的,如下:
然而,此时您应该问自己,与在gae / gke上运行您的应用程序(也许有不同的服务来分割关注点)相比,这是否真正有用,因为在成本方面可能会更便宜。
如果您想要一个针对“api网关”问题的SaaS解决方案,您还可以查看Apigee
您需要设置云负载均衡并使用云安全加密进行保护。然后在您的云函数上设置入口设置,仅接受内部流量和云负载均衡。