Search code examples
google-app-engineasp.net-coregoogle-cloud-datastoregoogle-cloud-platformapp-engine-flexible

Connecting to google datastore emulator with ASP.NET Core application


I am trying to configure the datastore emulator locally(running on windows) for development and testing as far as updating indexes in the cloud takes a lot of time. I am going step by step through this guide:

  1. gcloud beta emulators datastore start
  2. Should configure environment variables: just writing manually line by line set VARIABLE_NAME=VARIABLE_VALUE
  3. Trying to access localhost:8081 - returns Ok
  4. Trying to access localhost:8081/datastore - returns Not found
  5. Restarted application locally and trying some operations on datastore: all changes are applied on the cloud, not locally...

Solution

  • I have followed the same steps, but couldn't get it working unless I provided explicit instructions to DataStore's Create call.

    You need to differentiate whether your code is running in GCP vs Local.

    If you are in local environment, you need to create DataStoreDB as follows.

    DatastoreDb db = DatastoreDb.Create(projectId, string.Empty, new DatastoreClientImpl(
                    new Datastore.DatastoreClient(
                        new Channel("localhost", 8081, ChannelCredentials.Insecure)), new DatastoreSettings()));
    

    I am still exploring if you could do without initializing specifically to localhost