5
votes

I have a Google Pub/Sub project and created a topic and a simple subscription.

However, when specifying a URL for push, I keep getting the error below. I have completed the site verification process and registered the domain in APIs & services as described in https://cloud.google.com/pubsub/docs/push#other-endpoints:

ERROR: Failed to create subscription [projects/<project-id>/subscriptions/my-sub-2]: The supplied HTTP URL is not registered in the subscription's parent project (url="https://us-central1-<project-id>.cloudfunctions.net/xxxx", project_id="<project id number>").
ERROR: (gcloud.pubsub.subscriptions.create) Failed to create the following: [my-sub-2].

Please help !!

3
I assume you are running this in App Engine Standard, am I right? I saw that the error is creating subscriptions, have you follow this steps ? Can you add some snippet of your code so I can check if something is missing? Meanwhile, check this question and this one, as they seem related.Iñigo
It works if the subscription url is not a GCP Cloud Function endpoint. How to get GCP Cloud Pub/Sub to send messages to a Cloud Function endpoint?Edmund

3 Answers

1
votes

I walked into this issue numerous times, it is indeed really annoying. It is all about registering the ownership of the http endpoint. This way Google can verify that you are the owner of the supplied endpoint. Information on how to register the endpoint can be found here under domain ownership validation. I included this in my function so Google can verify the registration:

if request.method == 'GET':
    return '''
        <html>
            <head>
                <meta name="google-site-verification" content="{token}" />
            </head>
            <body>
            </body>
        </html>
    '''.format(token=config.SITE_VERIFICATION_CODE)
0
votes

Cloud functions can be set up to explicitly subscribe to a Cloud Pub/Sub topic as described here by setting the --trigger-topic command line parameter, which will not require explicit domain verification.

-2
votes

I was having this exact issue, but with app engine. Following this guide I was hitting the same error when creating the subscription like so:

gcloud pubsub subscriptions create <subscription_name> \
                --topic <topic_name> \
                --push-endpoint \
                    https://<PROJECT_ID>.appspot.com/_ah/push-handlers/receive_messages/token=<TOKEN> \
                --ack-deadline 30

After some experimentation and reading of some of the notes listed above (this one from Iñigo was especially useful), I realized that it wasn't that my URL was wrong, but that I didn't include the various project parameters in both the subscription and the topic.

This version worked for me:

gcloud pubsub subscriptions create projects/<PROJECT_ID>/subscriptions/<subscription_name> \
            --topic projects/<PROJECT_ID>/topics/<topic_name> \
            --push-endpoint \
                https://<PROJECT_ID>.appspot.com/_ah/push-handlers/receive_messages/token=<TOKEN> \
            --ack-deadline 30