LogoLogo
  • 🤩Welcome!
  • Buffer overflow
    • Remote Buffer Overflow
      • Crashing the Application
      • Controlling the EIP
      • Finding Bad Characters
      • Finding a Return Address
      • Generating Shellcode
      • Getting a Shell
  • Wireless Penetration Testing
    • Wifi Pineapple - Tetra
      • Setup
      • Firmware Upgrade
      • Capturing Wireless Handshake
      • Cracking WPA2 Handshake
      • PineAP
      • Modules
  • PortSwigger Labs
    • Authentication
      • Username enumeration via different responses
      • Username enumeration via subtly different responses
      • Username enumeration via response timing
  • TryHackMe
    • 🎄Advent of Cyber 3 (2021)
      • [Day 1] Save The Gifts
      • [Day 2] Elf HR Problems
      • [Day 3] Christmas Blackout
      • [Day 4] Santa's Running Behind
      • [Day 5] Pesky Elf Forum
      • [Day 6] Patch Management Is Hard
      • [Day 7] Migration Without Security
      • [Day 8] Santa's Bag of Toys
      • [Day 9] Where Is All This Data Going
  • Google Cloud Computing
    • ☁️Cloud Computing Fundamentals
      • Getting Started with Cloud Shell and gcloud
      • Creating a Virtual Machine
      • App Engine: Qwik Start - Python
      • Cloud Functions: Qwik Start - Command Line
      • Kubernetes Engine: Qwik Start
      • Set Up Network and HTTP Load Balancers
Powered by GitBook
On this page
  • Overview
  • Lab
  • Create a Function
  • Create a cloud storage Bucket
  • Deploy the Function
  • Test the Function
  • View Logs

Was this helpful?

  1. Google Cloud Computing
  2. Cloud Computing Fundamentals

Cloud Functions: Qwik Start - Command Line

LAB 4

PreviousApp Engine: Qwik Start - PythonNextKubernetes Engine: Qwik Start

Last updated 3 years ago

Was this helpful?

Overview

Cloud Functions is a serverless execution environment for building and connecting cloud services. With Cloud Functions you write simple, single-purpose functions that are attached to events emitted from your cloud infrastructure and services. Your Cloud Function is triggered when an event being watched is fired. Your code executes in a fully managed environment. There is no need to provision any infrastructure or worry about managing any servers.

Lab

Create a Function

create a simple function named helloWorld which writes a message to the Cloud Functions logs. It is triggered by cloud function events and accepts a callback function used to signal completion of the function.

For this lab the cloud function event is a cloud pub/sub topic event. A pub/sub is a messaging service where the senders of messages are decoupled from the receivers of messages. When a message is sent or posted, a subscription is required for a receiver to be alerted and receive the message. For more information about pub/subs, see .

First create a directory, move into it and create an index.js file.

mkdir gcf_hello_world
cd gcf_hello_world
touch index.js

Then, enter the following into the file.

/**
* Background Cloud Function to be triggered by Pub/Sub.
* This function is exported by index.js, and executed when
* the trigger topic receives a message.
*
* @param {object} data The event payload.
* @param {object} context The event metadata.
*/
exports.helloWorld = (data, context) => {
const pubSubMessage = data;
const name = pubSubMessage.data
    ? Buffer.from(pubSubMessage.data, 'base64').toString() : "Hello World";
console.log(`My Cloud Function: ${name}`);
};

Create a cloud storage Bucket

The following command creates a new bucket.

gsutil mb -p [PROJECT_ID] gs://[BUCKET_NAME]

gsutil mb -p qwiklabs-gcp-00-5cd73182d144 gs://neewashere

Deploy the Function

When deploying a new function, you must specify --trigger-topic, --trigger-bucket, or --trigger-http.

gcloud functions deploy helloWorld \
  --stage-bucket [BUCKET_NAME] \
  --trigger-topic hello_world \
  --runtime nodejs8
  
  gcloud functions deploy helloWorld \
  --stage-bucket neewashere \
  --trigger-topic hello_world \
  --runtime nodejs8

Verify the status of the function:

gcloud functions describe helloWorld

Test the Function

Enter the following command to create a message test of the function

DATA=$(printf 'Hello World! Neewashere'|base64) && gcloud functions call helloWorld --data '{"data":"'$DATA'"}'

View Logs

Check the logs to see your messages in the log history with the following command

gcloud functions logs read helloWorld

☁️
Google Cloud Pub/Sub: A Google-Scale Messaging Service