tmp dev
tmp dev

Reputation: 9193

gcp cloud function pub/sub topic dead letter

I am trying to achieve the following on gcp using terraform.

  1. A cloud function listens to messages added to a pub/sub topic
  2. Once a message is added the cloud function is triggered
  3. If there is an error in processing the message the message is put onto a corresponding dead letter queue.

I'm not sure how to create the subscription for the cloud function which also contains the dead letter policy. At the moment I'm doing the following for the cloud function,

resource "google_cloudfunctions_function" "brw-user-function-item-registered" {
 // details

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = "brw-messages"
    failure_policy {
      retry = false
    }
  }

 // details     
}

However there is no option to specify the dead-letter policy in the event_trigger section. If I create a separate google_pubsub_subscription I'm not sure how to give the endpoint to the cloud function. I had a look at what gets created and its actually an endpoint, however I'm not sure how to specify those details in the google_pubsub_subscription

Upvotes: 1

Views: 2098

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75735

You can't plug a function directly on a PubSub topic and define a deadletter topic. (same issue if you want to define filters on your subscription).

The solution is to create an HTTP functions, and to create separately a push subscription with a dead letter topic. 2 points of attention:

  • Take care to the security part, perform secure calls
  • The PubSub message format is slightly different from PubSub triggered cloud function and HTTP cloud function with PubSub push message.

In addition, keep in mind that the dead letter topic is used when at least 5 failures occur on the same message. The dead letter topic is not used at the first error returned by your Cloud Functions.

Upvotes: 3

Related Questions