Part-45: Cloud Functions with HTTPS in GCP – DEV Community




Google Cloud Functions – HTTPS Trigger

Step-01: Introduction

  1. Create Cloud Function with HTTP Trigger
  2. Access Cloud Function on browser and verify
  3. Review all settings in Cloud Run
  4. Edit Cloud Function to deploy v2.js file
  5. Access Cloud Function on browser with v2 version and verify
  6. Cloud Run Split Traffic between v1 and v2 and verify

Step-02: Create Cloud Function with HTTPS Trigger

Configuration Tab

f1

f2

  • Environment: 2nd gen (default – Cloud Run will select a suitable execution environment for you.)
  • Function name: cf-demo1-http
  • Region: us-central1
  • Trigger: HTTPS
  • Authentication: Allow unauthenticated invocations

f3

  • REST ALL LEAVE TO DEFAULTS
  • Click to NEXT

Code Tab

Runtime: Nodejs20 (default as on today)

f4

const functions = require('@google-cloud/functions-framework');

functions.http('helloHttp', (req, res) => {
  //res.send(`Hello ${req.query.name || req.body.name || 'World 101'}!`);
  res.send(`
    
    
    
      
      
      Cloud Functions Demo
    
    
      
      

Application Version: V1

`); });
Enter fullscreen mode

Exit fullscreen mode


Step-03: Access Application and Verify Cloud Run Service

# Access using Auto-generated URL
https://us-central1-kdaida123.cloudfunctions.net/cloud-function-demo1-http

# Cloud Run Service
1. Go to Cloud Run Service -> cf-demo1-http
2. Review the "Revisions" Tab
Enter fullscreen mode

Exit fullscreen mode

f5


Step-04: Deploy V2 of Cloud Function

  • Go to Cloud Functions -> cf-demo1-http -> Source -> Edit

Configuration Tab

Code Tab

  • Runtime: Nodejs20 (default as on today)
  • COPY the CODE and Deploy

f6

const functions = require('@google-cloud/functions-framework');

functions.http('helloHttp', (req, res) => {
  //res.send(`Hello ${req.query.name || req.body.name || 'World 101'}!`);
  res.send(`
    
    
    
      
      
      Cloud Functions Demo
    
    
      
      

Application Version: V2

`); });
Enter fullscreen mode

Exit fullscreen mode

f6


Step-05: Cloud Run – Revisions

Go to Cloud Run -> cf-demo1-http -> Revisions -> Manage Traffic

  • V1 Revision: 50%
  • V2 Revision: 50%

f7

Test it

f8

f9

Traffic’s are serving to the both revisions equally!



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *