Skip to content
Justin Digs Data
Justin Digs Data
  • Home
  • Nerd Library
Justin Digs Data
Google API Gateway Logo

API Key Authentication with Google Cloud API Gateway and Cloud Run

Posted on February 10, 2024February 15, 2024 By Justin

Table of Contents

Toggle
  • Introduction
      • WARNING
  • Basic Steps
  • Prerequisites
  • Google Cloud Setup
    • Enable Needed Google Cloud Services
      • Console Method
      • Command Line Method
    • Create a Google Cloud Service Account
      • Console Method
      • Command Line Method
  • Backend API Creation
    • Create a simple Python-based API
      • main.py
      • requirements.txt
      • Dockerfile
      • start.sh
    • Deploy Code as a Docker Container to Cloud Run
    • Testing
    • Reenable Authentication
    • Grant Service Account Permissions
  • API Gateway Setup
    • Create API Gateway API
    • Testing Your API
      • Cloud Run URL
      • API Gateway URL
      • GET Tests
      • POST Tests
  • Conclusion

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

  1. Browse to https://console.cloud.google.com/api-gateway/enable_api
  2. Select the appropriate project from the project selector dropdown at the top of the page
  3. 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
  4. Enter a descriptive Project name and select your Organization and Location
  5. Click the CREATE button
  6. Browse to https://console.cloud.google.com/apis/library/run.googleapis.com
  7. 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

Post navigation

Next post

Categories

  • AI
  • Backend Stuff

Recent Posts

  • An LLM’s Blog Post about Why You Shouldn’t Use LLMs to Write Blog Posts
  • API Key Authentication with Google Cloud API Gateway and Cloud Run

Archives

  • February 2024
©2025 Justin Digs Data | WordPress Theme by SuperbThemes