https://github.com/tsmx/cloudfunctionpubsub
Simple example project showing how to use GCP Cloud Functions for sending an email with a Pub/Sub Trigger.
https://github.com/tsmx/cloudfunctionpubsub
Last synced: 25 days ago
JSON representation
Simple example project showing how to use GCP Cloud Functions for sending an email with a Pub/Sub Trigger.
- Host: GitHub
- URL: https://github.com/tsmx/cloudfunctionpubsub
- Owner: tsmx
- License: mit
- Created: 2019-08-28T19:06:57.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-13T21:02:43.000Z (over 2 years ago)
- Last Synced: 2025-03-01T04:44:13.603Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 139 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CloudFunctionPubSub
A simple project showing how to implement a GCP cloud function triggered by a Pub/Sub topic.
## Contents
- function for sending an email is exported in the main module app.js
- Pub/Sub triggers the function and payload is served in event.data
- function awaits a JSON payload with structure: `{user: "username", subject: "subject"}`
- function send an email using credentials, sender and receiver from the config file (see config.js.example)
- function writes a log to stdout after the mail was sent, you can look it up at the GCP console
## Deploying and testing
To deploy run: `gcloud functions deploy sendMail --region europe-west1 --runtime nodejs10 --trigger-topic sendMail`.
This will:
- create & deploy the cloud function named "sendMail"
- create a new Pub/Sub topic "sendMail" if not present
- automatically add the cloud function as subscriber for this topic
To test run: `gcloud pubsub topics publish sendMail --message "{\"user\": \"testuser 2\", \"subject\": \"hello, cloud functions\"}"`.
- check the inbox provided in config.js.mailTo
- check the GCP logs