Push events to pubsub.

This commit is contained in:
Tom Alexander 2021-07-20 23:26:14 -04:00
parent f457cf2a6c
commit 7bf8370650
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 19 additions and 1 deletions

View File

@ -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
}

View File

@ -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
]

View File

@ -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):

View File

@ -1 +1,2 @@
Flask==1.1.2
google-cloud-pubsub==2.6.1