Push events to pubsub.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
Flask==1.1.2
|
||||
google-cloud-pubsub==2.6.1
|
||||
|
||||
Reference in New Issue
Block a user