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 Basic Steps This tutorial steps through an end-to-end walkthrough, including: Google Cloud Setup Enable Needed Google Cloud Services Create a Google Cloud Service Account Backend API Creation Create a simple Python-based API Deploy Code as a Docker Container to Cloud Run API Gateway Setup Create an API Gateway API Create an API Gateway Config Create an API Gateway Enable the API Gateway API Creating an API Key Test Your API Depending on your starting point, you might be able to skip several of these steps altogether. For example, if you already have an API deployed as a Cloud Run service, you can skip the Backend API Creation part. But because we need all of those pieces in order to demonstrate the end-to-end process, this tutorial includes a few extra steps to deploy a very simple Cloud Run service that serves up a couple basic endpoints: one that handles a simple GET request that just returns “Hello, World!”, another that listens for a POST and returns the sum of two numbers. Prerequisites The first four of these are only really needed for creating the simple Cloud Run service mentioned above. Again, if you already have a backend service deployed and/or you’re comfortable with that part, feel free to skip ’em. If you want to follow along exactly, you’ll need the: Backend API Development Python (and a few libraries we’ll install later) VS Code The Cloud Code for VS Code extension Docker API Gateway A Google Cloud account A Google Cloud project The Google Command Line Interface (gcloud CLI) The installation and configuration of each of those is out-of-scope for this post. And frankly, if you need a hand with that part of the process, you might not be quite ready for the rest of this yet. Pages: 1 2 3 4 5 6 7 8 9 10 11 12 Backend Stuff APICloud RunGCPPythonTutorial