Google local pubsub emulator not letting me create topics

2.9k Views Asked by At

I am following exactly the steps provided here https://cloud.google.com/pubsub/docs/emulator and it is giving me the following error on step number 4 of using the emulator steps.

So when I try to create a topic using googles python libraries as said in the link I get :

File "string", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 User not authorized to perform this action.

status = StatusCode.PERMISSION_DENIED
    details = "User not authorized to perform this action."
    debug_error_string = "{"created":"@1614133564.919217000","description":"Error received from peer ipv6:[2607:f8b0:4005:807::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"User not authorized to perform this action.","grpc_status":7}"

Why am I getting such an error if I am trying to work with the local pubsub emulator ?

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

It looks like the commands are not being run against the emulator, but against the actual service. The instructions say to run the steps "on the machine where you set the emulator environment variables." Did you follow the steps to set the environment variables in the doc it links to?

The sequence of commands you need to run first is:

$ gcloud beta emulators pubsub start --project=my-test-project

$ (gcloud beta emulators pubsub env-init)

This will start up the emulator and then set the environment variable PUBSUB_EMULATOR_HOST.