forked from MLSA-MUET-SZAB-Club-Khairpur-Mir-s/Cloud-Functions-Qwik-Start---Command-Line-30-minutes-Free
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCAMMANDS-LINE
More file actions
90 lines (58 loc) · 2.49 KB
/
CAMMANDS-LINE
File metadata and controls
90 lines (58 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
You can list the active account name with this command:
gcloud auth list
You can list the project ID with this command:
gcloud config list project
Create a function
To create a cloud function:
In the Cloud Shell command line, create a directory for the function code.
mkdir gcf_hello_world
Move to the gcf_hello_world directory.
cd gcf_hello_world
Create and open index.js to edit.
nano index.js
Copy the following into the index.js 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.
*/
Exit nano (Ctrl+x) and save (Y) the file.
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
Use the following command to create a new cloud storage bucket for your function:
gsutil mb -p [PROJECT_ID] gs://[BUCKET_NAME]
PROJECT_ID is the Project ID in the connection details of this lab
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will granted with an assessment score.
Deploy your function
When deploying a new function, you must specify --trigger-topic, --trigger-bucket, or --trigger-http. When deploying an update to an existing function,
the function keeps the existing trigger unless otherwise specified.
For this lab, you'll set the --trigger-topic as hello_world.
Deploy the function to a pub/sub topic named hello_world, replacing [BUCKET_NAME] with the name of your bucket:
gcloud functions deploy helloWorld \
--stage-bucket [BUCKET_NAME] \
--trigger-topic hello_world \
--runtime nodejs8
If prompted, enter Y to allow unauthenticated invocations of a new function.
Verify the status of the function.
gcloud functions describe helloWorld
An ACTIVE status indicates that the function has been deployed.
entryPoint: helloWorld
eventTrigger:
eventType: providers/cloud.pubsub/eventTypes/topic.publish
failurePolicy: {}
resource:
...
status: ACTIVE
...
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will receive an assessment score.