A Pub/Sub triggered Node.js Cloud Functions template.
Install dependencies:
npm install
Run the function:
npm start
...
> [email protected] start
> functions-framework --target=helloPubSub
Serving function...
Function: helloPubSub
Signature type: cloudevent
URL: http://localhost:8080/
Inside the scripts folder, run test_local.sh to test the function locally:
./test_local.sh
< HTTP/1.1 204 No Content
< Date: Tue, 21 Feb 2023 08:23:04 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
You should see the following in the function logs:
Event ID: 6308619096677818
Event Type: google.cloud.pubsub.topic.v1.messagePublished
TextData: Hello World
Subscription: projects/MY-PROJECT/subscriptions/MY-SUB
Run setup.sh to enable required services, grant the
pubsub.publisher
role to the Cloud Storage service account and create a Google
Cloud Storage (GCS) bucket:
./setup.sh
Run deploy.sh to deploy to Google Cloud:
./deploy.sh
Run test_cloud.sh to test the function in Google Cloud:
./test_cloud.sh
When you're done, you can cleanup created resources:
./cleanup.sh