Menu
Stuff by Yuki
  • Home
  • Data Engineering
    • Python
  • Business Intelligence
    • Power BI
    • Tableau
  • Perspectives
  • About
  • Contact
Stuff by Yuki

Deploying a Cloud Function using the Google Cloud CLI

Posted on October 27, 2022October 27, 2022

This is a short tutorial explaining how to deploy a cloud function using the google cloud CLI.

Set up Google Cloud CLI on your laptop

A prerequisite for this is that you have installed gcloud on your local machine. Check out this blog post that walks you through that process!

Deploying a Cloud Function using the Google Cloud CLI

  • First, let’s create a folder for this. Create a folder called “gcloud”. I’m using vscode for this walk-through but you can use your preferred text editor.
  • Next, add a python script called “main.py”. A cloud function needs to have main.py in order for it to work. It’s the main file that the cloud function executes. A function parameter “request” is needed for HTTP triggered cloud functions.

Here’s the snippets you can copy and paste:

Copy Copied Use a different Browser

def gcloud_test_function(request):
    return 'This is my test function!'

  • And you’ll type the following in the command line / terminal to deploy your cloud function. Please note that you configure each parameter differently depending on your needs. Go to this documentation for more information on that!
Copy Copied Use a different Browser

gcloud functions deploy my-test-function \
--gen2 \
--region=us-central1 \
--runtime=python39 \
--entry-point=gcloud_test_function \
--trigger-http

  • You might asked to enable the API if you’ve never created a cloud function before (you might’ve enabled already in GCP). After enabling that and run the above command, your function will be deployed! This is what I see in the command line / terminal:
  • Lastly, let’s make sure your cloud function has been successfully deployed. Go to cloud functions in your google cloud console. You should see your cloud function deployed.

That’s it! You’ve successfully deployed a cloud function from your local machine.

References:

  • google cloud documentation

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Where I’m Headed in the Next 5 Years
  • Open-Source vs Vendor Data Tools
  • Developing the Habit of Writing
  • How to Inspect and Optimize Query Plans in Python Polars
  • Learn Python Polars with Polars Cookbook

Popular Posts

  • A Running Total Calculation with Quick Measure in Power BI
  • A Complete Guide to Git Integration in Power BI
  • How To Copy And Paste Report Page in Power BI
  • Handling Missing Values in Polars
  • How to Convert String to Date or Datetime in Polars

connect with me

  • LinkedIn
  • Twitter
  • Github
  • Website

Search Articles

©2025 Stuff by Yuki | Powered by SuperbThemes