Cloud Functions: Qwik Start - Command Line
LAB 4
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 Google Cloud Pub/Sub: A Google-Scale Messaging Service.
First create a directory, move into it and create an index.js
file.
Then, enter the following into the file.
Create a cloud storage Bucket
The following command creates a new bucket.
Deploy the Function
When deploying a new function, you must specify --trigger-topic
, --trigger-bucket
, or --trigger-http
.
Verify the status of the function:
Test the Function
Enter the following command to create a message test of the function
View Logs
Check the logs to see your messages in the log history with the following command
Last updated