We can create a simple Google Cloud function from command line following these steps:
- Create a project with project ID as my-first-gcp-project-id
gcloud projects create 'heartin-gcp-project-id' --name='My First GCP Project'
You should see a response similar to as follows:
- Set the property project. You may set it for the current workspace by running:
gcloud config set project 'heartin-gcp-project-id'
You should see a response similar to the following:
- Enable Cloud Functions.
gcloud services enable cloudfunctions.googleapis.com
You should see a response similar to the following:
- Clone or download the Sample Code from the Git URL:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- Go to functions directory.
cd nodejs-docs-samples/functions/helloworld/
- Deploy the function.
gcloud functions deploy helloGET --runtime nodejs6 --trigger-http
You should see a response, as follows:
- Run the httpsTrigger URL from the previous section in a browser. You should see Hello World printed on the browser screen as follows:.