2
votes

I'm trying to forward a cloud function pubsub subscription to a dead letter topic as described here: https://cloud.google.com/pubsub/docs/dead-letter-topics#gcloud

I tried

$ gcloud pubsub subscriptions update gcf-worker-topic --dead-letter-topic=gcf-worker-dead-letter-topic

and also tried modifying the gcf-worker-topic subscription in the Console. Both gave me the same error:

ERROR: (gcloud.pubsub.subscriptions.update) INVALID_ARGUMENT: The supplied AppEngine URL project does not match the subscription's parent project

The goal is to forward messages to a dead letter queue when the cloud function crashes.

What am I doing wrong? Is this not supported? Are there plans for future support?

3

3 Answers

3
votes

When you plug directly your Cloud Function to a topic, an automatic push subscription is created with a strange endpoint:

https://d4d1290519676f29baf13a7bf18a25bf-dot-jea3ef1cff72566d8-tp.appspot.com/_ah/push-handlers/pubsub/projects/PROJECT_ID/topics/test-topic?pubsub_trigger=true

You can see that this URL is in appspot.com, which is typical of App Engine. So, the Cloud Function directly plugged to PubSub generate a strange Hack that use AppEngine in an external/google project. You can't update it.

The work around is to change your Cloud Function in HTTP triggered mode and to create a PubSub push subscription on it. However, be careful because the PubSub message format aren't exactly the same

  • With push subscription:
   {
     "message": {
       "attributes": {
         "key": "value"
       },
       "data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
       "messageId": "136969346945"
     },
     "subscription": "projects/myproject/subscriptions/mysubscription"
   }
0
votes

You might also need --dead-letter-topic-project. See the dosumentation.

0
votes

I believe that you are updating the topic id (gcf-worker-topic) instead of the subscription id.

It's in the subscription that the dead-letter-topic is defined. Try to create an new subscription:

gcloud pubsub subscriptions create subscription-id \
  --topic=gcf-worker-topic \
  --dead-letter-topic=gcf-worker-dead-letter-topic \
  --max-delivery-attempts=max-delivery-attempts \
  [--dead-letter-topic-project=dead-letter-topic-project]