Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Functions Public URL

How to set public route to HTTP GCF? So, currently the default path something like this.

https://us-central1-poised-breaker-162819.cloudfunctions.net/function-1

But I want to use it in this way

https://myfunction.com

or

https://myfunction.com/thisroute

So actually it is the question of namespacing or even proxying of the requests to appropriate function. How this can be achieved?

Update 1

It seems, like we can use an Endpoints service for that. But it still unclear would it work with GCF or not.

like image 497
QuestionAndAnswer Avatar asked Mar 30 '17 16:03

QuestionAndAnswer


People also ask

What is a HTTP function?

(HyperText Transfer Protocol) The communications protocol used to connect to Web servers on the Internet or on a local network (intranet). The primary function of HTTP is to establish a connection with the server and send HTML pages back to the user's browser.


1 Answers

Cloud Endpoints acts as an API gateway for cloud functions.

For Cloud function https://[CLOUD_FUNCTION_REGION].cloudfunctions.net/my-function,

  1. Set project id in Cloud shell

    gcloud config set project [PROJECT_ID]
    
  2. 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)

  3. 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
    
  4. Deploy Endpoint configuration:

    gcloud endpoints services deploy api.yaml
    
  5. Now, Cloud function request can route through endpoint https://CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app/thisroute.

  6. Also to use custom domain name, need to verifying a domain name. For that follow steps from here

like image 174
Gautam Savaliya Avatar answered Sep 17 '22 12:09

Gautam Savaliya