Menu
Stuff by Yuki
  • Home
  • Python
  • Power BI
  • Tableau
  • Community
    • Makeover Monday
    • Workout Wednesday
  • 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

  • What are Power BI Dataflows?
  • Calculate the Max Sales Amount for Product
  • Convert DataFrame to Series in Polars
  • Pandas vs Polars – Speed Comparison
  • Polars with DuckDB – Using SQL in Polars

Popular Posts

  • A Running Total Calculation with Quick Measure in Power BI
  • How To Copy And Paste Report Page in Power BI
  • Year-Over-Year Calculation: Time Intelligence in Power BI
  • How to Fill Dates Between Start Date and End Date in Power BI (Power Query)
  • Network Visualizations in Python

connect with me

  • LinkedIn
  • Twitter
  • Github
©2023 Stuff by Yuki | Powered by SuperbThemes & WordPress