Google Cloud Endpoints with Google Cloud Run
I will follow this tutorial.
- In the GCP console go to the Manage resources page and create a project.
- Enable billing to the project following this tutorial.
- Make a note of the project ID and project NUMBER. On the rest of this page, this project ID and project NUMBER is referred to as PROJECT_ID and PROJECT_NUMBER.
- Download and install the Google Cloud SDK following this tutorial.
- Go to Google Cloud Run page.
- Click Create service to display the Create service form.
- Use
gcr.io/cloudrun/hello
as a container image. - Select the region where you want your service located.
- Check Allow unauthenticated invocations to be able to open the result in your web browser.
- Click Create to deploy the image to Cloud Run and wait for the deployment to finish.
- Click the displayed URL link to run the deployed container.
Run the command:
gcloud beta run deploy SERVICE_NAME --image=gcr.io/endpoints-release/endpoints-runtime-serverless:1.30.0 --allow-unauthenticated --region=us-central1 --project=PROJECT_ID
replace SERVICE_NAME
and PROJECT_ID
. Take note of the hostname in the URL.
- Make a copy of
openapi-run.yaml.example
toopenapi-run.yaml
. - Replace
my.esp.host
to your ESP hostname. Don't include the protocol identifierhttps://
. - Replace
https://my.backend.service.url
to your URL of your backend service.
Run the command:
gcloud endpoints services deploy openapi-run.yaml --project PROJECT_ID
replace PROJECT_ID
.
- gcloud beta run services update
SERVICE_NAME
--set-env-vars ENDPOINTS_SERVICE_NAME=HOST
--region us-central1 --projectPROJECT_ID
- gcloud beta run services add-iam-policy-binding
BACKEND_SERVICE
--member serviceAccount:PROJECT_NUMBER
-compute@developer.gserviceaccount.com --role roles/run.invoker --projectPROJECT_ID
- replace
SERVICE_NAME
to ESP service name. - replace
HOST
to cloud endpoints host. - replace
PROJECT_ID
andPROJECT_NUMBER
. - replace
BACKEND_SERVICE
to your backend on Cloud Run.
Run a command:
curl --request GET --header "content-type:application/json" "https://${ENDPOINTS_HOST}/hello"
replace ${ENDPOINTS_HOST}
to host value on endpoints configuration.