Push events to pubsub.

master
Tom Alexander 3 years ago
parent f457cf2a6c
commit 7bf8370650
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -207,6 +207,7 @@ module "cf_to_pubsub" {
source = "../modules/cf_to_pubsub"
project = var.project
region = var.region
topic_name = "bigquery-etl"
source_bucket = google_storage_bucket.bucket
service_cloudbuild = google_project_service.cloudbuild
}

@ -11,6 +11,11 @@ variable "region" {
type = string
}
variable "topic_name" {
description = "The name of topic where the events should be published."
type = string
}
variable "source_bucket" {
description = "Google storage bucket where the source code will be stored."
}
@ -61,6 +66,11 @@ resource "google_cloudfunctions_function" "function" {
ingress_settings = "ALLOW_ALL"
# ingress_settings = "ALLOW_INTERNAL_ONLY"
environment_variables = {
GCP_PROJECT = var.project
GCP_TOPIC = var.topic_name
}
depends_on = [
var.service_cloudbuild
]

@ -1,8 +1,14 @@
import json
import os
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
topic = publisher.topic_path(os.environ.get("GCP_PROJECT"), os.environ.get("GCP_TOPIC"))
def push_to_pubsub(request_params):
print(json.dumps(request_params))
publisher.publish(topic, json.dumps(request_params).encode("utf-8")).result()
def main(request):

Loading…
Cancel
Save