Last active
October 12, 2022 19:03
-
-
Save nishitpatel01/f4bc570abaa06b42adb711e1cb9d5336 to your computer and use it in GitHub Desktop.
Create cloud function and pubsub topics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGION = "your-cloud-function-region" | |
TOPIC_NAME = "sensor-data-processing" | |
SOURCE_URI = "cloud-function-file-directory" | |
ENTRY_POINT = "detect_anomaly" | |
# create to pub/sub topic | |
gcloud pubsub topics create TOPIC_NAME | |
# Create cloud function | |
gcloud functions deploy sensor-data-processing \ | |
--runtime=python310 \ | |
--region=REGION \ | |
--source=SOURCE_URI \ | |
--entry-point=ENTRY_POINT \ | |
--trigger-topic=TOPIC_NAME \ | |
--allow-unauthenticated | |
# Create query payload | |
query_payload = { | |
"attributes": { | |
"time": "1664826843", | |
"temperature": "34.18", | |
"light": "23", | |
"h2_raw": "1040", | |
"humidity": "26", | |
"dataset": "sensor-data", | |
"metric": ["temp"], | |
"forecast_history": "43000s", | |
"granularity": "600s", | |
"noise_threshold": "100.0", | |
"anomaly_threshold": "1.0" | |
} | |
} | |
# Publish message to cloud function | |
gcloud pubsub topics publish TOPIC_NAME --message=query_payload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment