Google Cloud Pub/Sub Emulator: user not authorized creating a new topic

938 Views Asked by At

I'm using google-cloud-pubsub in Django and the Google Cloud Pub/Sub Emulator. I'm trying to create a topic in this way:

publisher = pubsub.PublisherClient ()
topic_path = publisher.topic_path ('my-project', 'my-new-topic')
topic = publisher.create_topic (topic_path)
topic.publish (topic, request.data ['url']. encode ('utf-8'))

but it gives me this exception:

StatusCode.PERMISSION_DENIED, User not authorized to perform this action.

I'm wondering if there is anything else to configure except the PUBSUB_EMULATOR_HOST environment variable. Do I have to set some permissions, even for the emulator? The tutorial doesn't explain much more.

Thanks in advance.

1

There are 1 best solutions below

0
On

4 years late :) but this should solve it:

export PUBSUB_EMULATOR_HOST=localhost:8085

Why

The command in google tutorial (gcloud beta emulators pubsub env-init) for some reason doesn't set the environment variable. So your pubsub apis call the service account instead of the local emulator which result in permission errors.

Manually set it and verify it's set using echo $PUBSUB_EMULATOR_HOST