-
Notifications
You must be signed in to change notification settings - Fork 361
/
Cloud Functions: Qwik Start - Command Line
59 lines (47 loc) · 1.45 KB
/
Cloud Functions: Qwik Start - Command Line
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
export REGION=
gcloud config set compute/region $REGION
mkdir gcf_hello_world && cd $_
cat > index.js <<'EOF_END'
const functions = require('@google-cloud/functions-framework');
// Register a CloudEvent callback with the Functions Framework that will
// be executed when the Pub/Sub trigger topic receives a message.
functions.cloudEvent('helloPubSub', cloudEvent => {
// The Pub/Sub message is passed as the CloudEvent's data payload.
const base64name = cloudEvent.data.message.data;
const name = base64name
? Buffer.from(base64name, 'base64').toString()
: 'World';
console.log(`Hello, ${name}!`);
});
EOF_END
cat > package.json <<'EOF_END'
{
"name": "gcf_hello_world",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0"
}
}
EOF_END
npm install
gcloud services disable cloudfunctions.googleapis.com
gcloud services enable cloudfunctions.googleapis.com
sleep 15
gcloud functions deploy nodejs-pubsub-function \
--gen2 \
--runtime=nodejs20 \
--region=$REGION \
--source=. \
--entry-point=helloPubSub \
--trigger-topic cf-demo \
--stage-bucket $DEVSHELL_PROJECT_ID-bucket \
--service-account cloudfunctionsa@$DEVSHELL_PROJECT_ID.iam.gserviceaccount.com \
--allow-unauthenticated \
--quiet
gcloud functions describe nodejs-pubsub-function \
--region=$REGION