Google Cloud Function - Hello World (gcloud)
In this post, I am going to create a test Cloud Function on CLI, based on the tutorial: https://cloud.google.com/functions/docs/tutorials/http .
For the browser equivalent, see Google Cloud Function - Hello World (Browser).
install gcloud
The CLI tool is included in the Google Cloud SDK.
% brew install google-cloud-sdk% source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc% gcloud --versionGoogle Cloud SDK 339.0.0
bq 2.0.67
core 2021.04.30
gsutil 4.61
init config & create project
% gcloud initYou must log in to continue. Would you like to log in (Y/n)? Y
Pick cloud project to use: (Create a new project)
Enter a Project ID: foo20210509
Check the status:
% gcloud config configurations list
% gcloud config list
enable billing
"This command is currently in ALPHA and may change without notice" (https://cloud.google.com/sdk/gcloud/reference/alpha/billing)
% gcloud alpha billing accounts listACCOUNT_ID NAME OPEN MASTER_ACCOUNT_ID
xxxxxx-xxxxxx-xxxxxx My Billing Account True
% gcloud alpha billing projects link foo20210509 --billing-account xxxxxx-xxxxxx-xxxxxx
enable Cloud Build API
https://cloud.google.com/sdk/gcloud/reference/services/enable
% gcloud services list --available | grep 'Cloud Build API'
cloudbuild.googleapis.com Cloud Build API
% gcloud services enable cloudbuild.googleapis.comcreate cloud function
Download the sample application.
% git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
% cd python-docs-samples/functions/helloworld/
% cat main.py
Deploy
% gcloud functions deploy hello_get --runtime python38 --trigger-http --allow-unauthenticatedCheck
% gcloud functions list
NAME STATUS TRIGGER REGION
hello_get ACTIVE HTTP Trigger us-central1
% gcloud functions describe hello_get | grep 'url:'
url: https://us-central1-foo20210509.cloudfunctions.net/hello_get
% curl https://us-central1-foo20210509.cloudfunctions.net/hello_get
Hello World!
cleanup
function
% gcloud functions delete hello_get
% gcloud functions list
project
% gcloud projects delete foo20210509
% gcloud projects list
"After approximately 30 days, the project is fully deleted" (https://cloud.google.com/resource-manager/docs/creating-managing-projects)
Comments
Post a Comment