API Key Authentication with Google Cloud API Gateway and Cloud Run Posted on February 10, 2024February 15, 2024 By Justin Table of Contents Toggle IntroductionWARNINGBasic StepsPrerequisitesGoogle Cloud SetupEnable Needed Google Cloud ServicesConsole MethodCommand Line MethodCreate a Google Cloud Service AccountConsole MethodCommand Line MethodBackend API CreationCreate a simple Python-based APImain.pyrequirements.txtDockerfilestart.shDeploy Code as a Docker Container to Cloud RunTestingReenable AuthenticationGrant Service Account PermissionsAPI Gateway SetupCreate API Gateway APITesting Your APICloud Run URLAPI Gateway URLGET TestsPOST TestsConclusion Google Cloud Setup Enable Needed Google Cloud Services There are a handful of services you’ll need to activate in your Google Cloud project in order to use the API Gateway: API Gateway API Service Management API Service Control API Cloud Run* * Required for this specific tutorial, but not necessary if you’re using a different service to host your API. Console Method Browse to https://console.cloud.google.com/api-gateway/enable_api Select the appropriate project from the project selector dropdown at the top of the page For each of the three services listed (that don’t already have a green check mark): Click LAUNCH to open the product details page Click ENABLE to activate the API in your project Enter a descriptive Project name and select your Organization and Location Click the CREATE button Browse to https://console.cloud.google.com/apis/library/run.googleapis.com Click ENABLE Command Line Method gcloud services enable apigateway.googleapis.com --project={{PROJECT_ID}} gcloud services enable servicemanagement.googleapis.com --project={{PROJECT_ID}} gcloud services enable servicecontrol.googleapis.com --project={{PROJECT_ID}} gcloud services enable run.googleapis.com --project={{PROJECT_ID}} Where: {{PROJECT_ID}}: Name of the Google Cloud project you’re using for the tutorial. In my examples, I’ve created a project called api-gateway-key-auth-demo Pages: 1 2 3 4 5 6 7 8 9 10 11 12 Backend Stuff APICloud RunGCPPythonTutorial