0

I want to deploy cloud function that is triggerred by pubsub eventarc trigger using gcloud command line, but I haven't found a way to specify the pubsub topic with the gcloud command.

I have tried executing gcloud command like this :

gcloud functions deploy <function_name> \
--gen2 \
--source=. \
--trigger-event-filters=type=google.cloud.pubsub.topic.v1.messagePublished \
--trigger-location=asia-southeast2 \
--trigger-service-account=<service_account> \
--runtime=python310 \
--entry-point=hello_pubsub \
--project=<project_id> \
--region=asia-southeast2

But I got this error :

gcloud.functions.deploy) INVALID_ARGUMENT: Pubsub topic must be set for events with type google.cloud.pubsub.topic.v1.messagePublished.

I have checked GCP documentation eventarc cloud function documentation, but they do not mention on how to specify the pubsub topic.

My objective is to call this gcloud command from the cloud build pipeline to automatically deploy the cloud function.

Thank You

ramaadhitia
  • 303
  • 1
  • 12

1 Answers1

1

You can use --trigger-topic to specify the topic.

gcloud functions deploy <function_name> \
--gen2 \
--source=. \
--trigger-topic=topic_name
....

The --trigger-event-filters can be used to filter out events based on any other attributes. Checkout the linked documentation for more information.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • It doesn't seems so. I got this error when I specified trigger-topic flags : "At most one of --trigger-bucket | --trigger-http | --trigger-topic | --trigger-event --trigger-resource | --trigger-event-filters --trigger-event-filters-path-pattern --trigger-channel can be specified. " – ramaadhitia Jan 15 '23 at 05:10
  • @ramaadhitia right, as the error suggests, you don't need `trigger-event-filters` along with topic name. I missed that while removing other flags. The same is mentioned in the linked docs. – Dharmaraj Jan 15 '23 at 05:24
  • Thank you this works. the --trigger-event-filters flag has to be removed indeed – ramaadhitia Jan 15 '23 at 05:38