Google App Engine lets you build and run your own custom applications on Google’s servers. App Engine applications are easy to create, maintain, and scale as your traffic and data storage needs change. You simply upload your application source code and it’s ready to go. If you're new to developing for App Engine, be sure to check out the App Engine Python or Node.js quickstart before proceeding.
Earth Engine and App Engine can be used together to build scalable geospatial
applications. Typically, your App Engine code includes the
Engine Python client library and makes requests to the Earth Engine backend using a
service account. This is advantageous because it allows
anyone to use your app without logging in or being a registered Earth Engine user.
Note that the standard Earth Engine usage limits apply to each service
account. If you expect your application to be popular and approach the usage limits,
please contact the Earth Engine team (
firstname.lastname@example.org) before launching
Another development approach is to use client-side authentication instead of a service account. With this approach, visitors to your application must be whitelisted for Earth Engine and log in. The benefit of this approach is that requests to Earth Engine are made using the end user's credentials, so you are less likely to hit usage limits. The challenge is that your users must signup for Earth Engine and log in before using the application.
The Earth Engine App Engine demos directory on GitHub contains a set of useful App Engine examples. See the Example Apps page for a brief description of each example. This doc provides instructions for how to set up and deploy the examples or custom apps you create.
Deploying App Engine apps with Earth Engine
1. Create your own project
Each App Engine app needs its own project. To deploy your own instance, you'll need
to have a project with a unique ID (e.g.
foo-ee-project). This guide
assumes that you will create a new project.
To create an App Engine project for your app:
- Use the Google Cloud Console to create a new project. (You may need to accept the terms of service as part of this process.)
- Enter a project name. (Note that the project name is distinct from the project ID. The project ID is based on the name by default, but you can edit the ID independently of the name by clicking Edit.)
- Click CREATE.
- If prompted, choose a region close to the users for your app.
2. Set up credentials
account is used to authorize requests to Earth Engine on behalf of whomever
is using your app. The
config.py file contains authentication code
using the service account email address and a private key file. To set up
authentication with a service account:
- Create and authorize a service account.
- Download a private key file associated with your app's service account and move it
into your project directory. Rename the key file
- Test the service account authentication flow by running one of the following commands.
If you haven't already, first install the Earth Engine Python API.
service_account = 'my-service-account-id@...gserviceaccount.com' credentials = ee.ServiceAccountCredentials(service_account, 'privatekey.json') ee.Initialize(credentials)
If the test succeeds, update
config.py (or an equivalent file in your source
code) with your service account email address. (The path to the key file should not change
since it's in your project directory).
Install the project's dependencies by running
npm install. The Earth Engine
Node.js API and any other dependencies will be copied to a
folder in your project directory. If installation fails, check that
a recent version of Node.js is installed.
const ee = require('@google/earthengine'); ee.data.authenticateViaPrivateKey('privatekey.json'); ee.initialize();
OAuth 2.0 Client ID
If you want users to authenticate as themselves (rather than using a service account), you need to set up an OAuth Client ID. To do that:
- From the menu in the upper left of the Developers Console, choose APIs & Services > Credentials. Click Create credentials > OAuth client ID and select Web application.
origins, for example:
- Specify authorized redirect URIs, for example:
static/script.js(or an equivalent file in your source code) to use your client ID.
ee_api_js.jsis available in the
/static/directory (or equivalent). You can download it directly from GitHub, install it from npm, or, if you've already cloned the entire EE API repo, copy it from
Check out the Google Identity OAuth documentation for a more detailed explanation of OAuth.
3. Set up the local development environment
Follow the instructions in each example directory on GitHub to download and build the
project. If there's a
build.sh file, run it from your application root
folder with the command:
The setup script will download dependencies and install Google command line tools, if
they don't already exist on your system. The Earth Engine Python API and its
dependencies will be copied to a
./lib folder in your project directory.
Verify that the App Engine command line tools are available by running:
If the command is not found, try manually downloading and installing the Google App Engine SDK for Python. If the command is available, it should fail with "error: too few arguments".
Also verify that the crypto library is installed with:
python -c "from oauth2client import crypt"
If an error is returned, install pyCrypto into your local Python distribution. For
sudo pip install pyCrypto
No setup needed.
4. Run locally
Once your service account is whitelisted
for Earth Engine access, you can use it to authenticate (see
when you test the examples. Try testing the examples locally first by going into your
project directory and running:
Point your browser to http://localhost:8080 to see the app running on a local server. Any changes you make (and save) will be automatically picked up when you refresh the page.