2

I have a deployed app using Google App Engine for Java. How can I use the remote Datastore (from production) with a local development server?

My question is very similar to that one, only I'm asking about Java and not Python.

1
  • Whats your use case? you could depoly your app to a different project id, and use datastore admin to clone the datastore from one project to the new one. By the way i'm pretty sure that bulkloader.py solution from the question you linked is just a standalone script you can run. it doesn't matter that your project is in java. Commented Aug 16, 2017 at 16:49

1 Answer 1

2

Local program can be authonticated by service-account.

Here and here is docs about how to use service-account in java program.

Use env variable:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json

Or supply the JSON credentials file:

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.Entity;
import com.google.cloud.datastore.Key;
import com.google.cloud.datastore.KeyFactory;

DatastoreOptions options = DatastoreOptions.newBuilder()
  .setProjectId(PROJECT_ID)
  .setCredentials(GoogleCredentials.fromStream(
    new FileInputStream(PATH_TO_JSON_KEY))).build();
Datastore datastore = options.getService();
KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND);
Key key = keyFactory.newKey(keyName);
Entity entity = datastore.get(key);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.