2022-07-02

Cloud Functions Tutorial

Introduction

In this article, I will demonstrate how to create and deploy a sample Cloud Functions function.

Create a Function

  1. First, go to the Google Cloud Functions console and click the "CREATE FUNCTION" button.

Tutorial 1

  1. Enter any function name in the "Function name" field, and click the "SAVE" button.

Tutorial 2

  1. Click the "NEXT" button.

Tutorial 3

  1. Write the code. For this tutorial, we will leave it as default and click the "DEPLOY" button.

Tutorial 4

Execute the Function

  1. Attach a role that can execute the created function.
bash
$ gcloud alpha functions add-iam-policy-binding sample-func \
  --region=us-central1 \
  --member=allUsers \
  --role=roles/cloudfunctions.invoker
  1. Get the trigger URL for the created function.
bash
$ gcloud functions describe demo-function --region us-central1 | grep url
  1. Send a POST request to the trigger URL.
bash
$ curl -X POST <trigger URL> \
   -H 'Content-Type:application/json' \
   -d '{"message":"Hello World!"}'

This will execute the function and return a response.

Hello World!

References

https://www.cloudskillsboost.google/focuses/1763?parent=catalog
https://www.cloudskillsboost.google/focuses/916?parent=catalog

Ryusei Kakujo

researchgatelinkedingithub

Focusing on data science for mobility

Bench Press 100kg!