Search code examples
c#.netemulationgoogle-cloud-bigtable

Cannot connect to Bigtable Emulator from C# client


I have the Google Bigtable Emulator running on my local machine and listening on port 8086.

Using the C# Google.Cloud.Bigtable.Admin.V2 library I want to connect to the emulator like this:

using Google.Cloud.Bigtable.Admin.V2;
using NUnit.Framework;
Assert.AreEqual("127.0.0.1:8086", Environment.GetEnvironmentVariable("BIGTABLE_EMULATOR_HOST"));
var client = await BigtableTableAdminClient.CreateAsync();

Despite setting the environment variable as described in the emulator documentation, the library still seems to expect (cloud) credentials. I get the following error:

The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

What's the proper way to set the credentials when using the local emulator?


Solution

  • Google Cloud SDK for .NET has delayed emulator support. In v3.0.0, support seems to have arrived as far as the code is concerned. Please try the following code:

    Google.Cloud.Bigtable.Admin.V2 2.9.0:

                var admin = Environment.GetEnvironmentVariable("BIGTABLE_EMULATOR_HOST") switch
                {
                    null => throw new InvalidOperationException("Must use emulator"),
                    var host => new BigtableTableAdminClientBuilder() { CallInvoker = new GcpCallInvoker(host, ChannelCredentials.Insecure) }.Build(),
                };
    

    Google.Cloud.Bigtable.Admin.V2 3.0.0:

                var admin = new BigtableTableAdminClientBuilder { EmulatorDetection = EmulatorDetection.EmulatorOnly }.Build();