Skip to content

Instantly share code, notes, and snippets.

@nishitpatel01
Last active October 12, 2022 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishitpatel01/f4bc570abaa06b42adb711e1cb9d5336 to your computer and use it in GitHub Desktop.
Save nishitpatel01/f4bc570abaa06b42adb711e1cb9d5336 to your computer and use it in GitHub Desktop.
Create cloud function and pubsub topics
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