cloud functions in gcp

gcloud function is similar to serverless concept  
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
Cloning into ‘nodejs-docs-samples’…
remote: Enumerating objects: 89, done.
remote: Counting objects: 100% (89/89), done.
remote: Compressing objects: 100% (87/87), done.
remote: Total 13383 (delta 39), reused 2 (delta 0), pack-reused 13294
Receiving objects: 100% (13383/13383), 14.61 MiB | 2.31 MiB/s, done.
Resolving deltas: 100% (8460/8460), done.

cd nodejs-docs-samples/functions/helloworld/

ls
index.js index.pug package.json README.md shim.js test
cat index.js
/**
* Copyright 2018, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

‘use strict’;

const Buffer = require(‘safe-buffer’).Buffer;

// [START functions_helloworld_http]
const escapeHtml = require(‘escape-html’);

 

gcloud functions deploy helloGET –runtime nodejs6 –trigger-http
Deploying function (may take a while – up to 2 minutes)…done.
availableMemoryMb: 256
entryPoint: helloGET
httpsTrigger:
url: https://us-central1-evident-axle-224004.cloudfunctions.net/helloGET
labels:
deployment-tool: cli-gcloud
name: projects/evident-axle-224004/locations/us-central1/functions/helloGET
runtime: nodejs6
serviceAccountEmail: evident-axle-224004@appspot.gserviceaccount.com
sourceUploadUrl: https://storage.googleapis.com/gcf-upload-us-central1-1c2dda91-9d86-48a2-96ee-d0bbfac9f7b6/e12ecb91-de6c-43d8-b98c-89ead6ec335e.zip?GoogleAccessId=service-353146634422@gcf-admin-robot.iam.gservice
account.com&Expires=1551888999&Signature=wQHu2GcHLd9Kc1a1xMmHXDC%2FFR1A%2FZg01jA4AQc491t1rPiroSAGnWcFMYQ9a8aHootwCF4CP%2FKQoOZZc14wVHJTzhwsMh7VosN2mlx%2FEgoFYCvrpuaV7hNI0ndcnC5OtML2Iyvl%2Bc64VkZiCnYy%2B14WNDAFvsf3
3zgElWWhZSEMmI%2BmxIjl841NJ2Jxkeg1%2FktmuW9HgZde5lVxVxvTqZgeLwTWp107K738mSGhwNcVBi0M6T8aKGJQVP8fH8jUgEVg1Hm2yNEYpHtFlGJFhgBCkSJnQU3KrgrdFxk4be8OLr%2FZchp%2FMo8Ili5%2FJRC9WIXyr%2BtFN9wh%2B8YtOzoTdw%3D%3D
status: ACTIVE
timeout: 60s
updateTime: ‘2019-03-06T15:48:22Z’

gcp-cloud-function-1

You can test your function like this

gcp-cf-2

We can view the log & output of a function after trigger

gcp-cf-3

 

gcp-cf-4

Here we can seen spike here when the function ran .

gcp-cf-5

 

 

Leave a comment