GithubHelp home page GithubHelp logo

jkeifer / stac-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stac-utils/stac-server

0.0 1.0 1.0 11.16 MB

A Node-based STAC API, AWS Serverless

License: Other

JavaScript 98.93% Shell 1.07%

stac-server's Introduction

stac-server

Overview

Stac-server is an implementation of the STAC API specification for searching and serving metadata for geospatial data, including but not limited to satellite imagery). The STAC and STAC API versions supported by a given version of stac-server are shown in the table below. Additional information can be found in the CHANGELOG

stac-server Version STAC Version STAC API Version
0.1.x 0.9.x 0.9.x
0.2.x <1.0.0-rc.1 0.9.x
0.3.x 1.0.0 1.0.0-beta.2
0.4.x 1.0.0 1.0.0-beta.5

The following APIs are deployed instances of stac-server:

| Name | STAC Version | STAC API Version | Description | | ---------------------------------------------------------- | ------------ | ---------------- | | Earth Search | 1.0.0-beta.2 | 0.9.0 | Catalog of some AWS Public Datasets | | Landsat Look | 1.0.0 | 0.9.0 | | | USGS Planetary Catalog | 1.0.0 | | USGS Astrogeology hosted Analysis Ready Data (ARD) |

Architecture

flowchart LR

itemsForIngest[Items for ingest]

subgraph ingest[Ingest]
  ingestSnsTopic[Ingest SNS Topic]
  ingestQueue[Ingest SQS Queue]
  ingestLambda[Ingest Lambda]

  ingestDeadLetterQueue[Ingest Dead Letter Queue]
  failedIngestLambda[Failed Ingest Lambda]
end

users[Users]

subgraph api[STAC API]
  apiGateway[API Gateway]
  apiLambda[API Lambda]
end

elasticsearch[(Elasticsearch)]

%% Ingest workflow

itemsForIngest --> ingestSnsTopic
ingestSnsTopic --> ingestQueue
ingestQueue --> ingestLambda
ingestLambda --> elasticsearch

ingestDeadLetterQueue --> failedIngestLambda

%% API workflow

users --> api
apiGateway --> apiLambda
apiLambda --> elasticsearch

Loading

Migration

0.3 -> 0.4

The Serverless Framework supports provisioning AWS resources, but it does not support updating existing resources. In 0.4, the default Elasticsearch version has been updated from 7.9 to 7.10. Continuing to use 7.9 should not cause any problems, but it recommended that you manually upgrade to 7.10 by going to AWS Console - Amazon OpenSearch Service, choosing the Elasticsearch domain used by your stac-server deployment (e.g., stac-server-{stage}-es), choose Upgrade from the Actions menu, and then upgrade to Elasticsearch 7.10.

Usage

Stac-server is a web API that returns JSON, see the documentation, or the /api endpoint which is a self-documenting OpenAPI document. Here are some additional tools that might prove useful:

  • pystac-client: A Python client library and CLI for searching a STAC compliant API

Deployment

This repository contains Node libraries for running the API, along with a serverless configuration file for deployment to AWS.

To create your own deployment of stac-server, first clone the repository:

git clone https://github.com/stac-utils/stac-server.git
cd stac-server

Copy the example serverless config file to a file named serverless.yml:

cp serverless.yml.example serverless.yml

There are some settings that should be reviewed and updated as needeed in the serverless config file, under provider->environment:

Name Description Default Value
STAC_VERSION STAC Version of this STAC API 1.0.0
STAC_ID ID of this catalog stac-server
STAC_TITLE Title of this catalog STAC API
STAC_DESCRIPTION Description of this catalog A STAC API
STAC_DOCS_URL URL to documentation https://stac-utils.github.io/stac-server
ES_BATCH_SIZE Number of records to ingest in single batch 500
LOG_LEVEL Level for logging (CRITICAL, ERROR, WARNING, INFO, DEBUG) INFO
STAC_API_URL The root endpoint of this API Inferred from request
ENABLE_TRANSACTIONS_EXTENSION Boolean specifying if the Transaction Extension should be activated false

After reviewing the settings, build and deploy:

npm install
npm run build
npm run deploy

This will create a CloudFormation stack in the us-west-2 region called stac-server-dev. To change the region or the stage name (from dev) provide arguments to the deploy command (note the additional -- in the command, required by npm to provide arguments):

npm run deploy -- --stage mystage --region eu-central-1

Once deployed there is one final step - creating the indices and mappings in Elasticsearch. Invoke the stac-server-<stage>-ingest Lambda function with a payload of:

{
  "create_indices": true
}

This can be done with the AWS CLI with (the final - parameter pipes the output to stdout):

aws lambda invoke \
  --function-name stac-server-dev-ingest \
  --cli-binary-format raw-in-base64-out \
  --payload '{ "create_indices": true }' \
  -

Stac-server is now ready to ingest data!

Ingesting Data

STAC Collections and Items are ingested by the ingest Lambda function, however this Lambda is not invoked directly by a user, it consumes records from the stac-server-<stage>-queue SQS. To add STAC Items or Collections to the queue, publish them to the SNS Topic stac-server-<stage>-ingest.

STAC Collections should be ingested before Items that belong to that Collection. Items should have the collection field populated with the ID of an existing Collection.

Ingesting large items

There is a 256 KB limit on the size of SQS messages. Larger items can by publishing a message to the stac-server-<stage>-ingest SNS topic in with the format:

{
  "href": "s3://source-bucket/source-key"
}

The s3://, http://, and https:// protocols are supported for remote ingest.

Subscribing to SNS Topics

Stac-server can also be subscribed to SNS Topics that publish complete STAC Items as their message. This provides a way to keep stac-server up to date with new data. Use the AWS Lambda console for the function stac-server-<stage>-subscibe-to-sns to subscribe to an SNS Topic for which you have the full ARN and permission to subscribe to. This could be an SNS Topic you created yourself to publish STAC records to, or a publicly available one, such as for Sentinel.

Note, that adding the subscription via the topic page does not seem to work. Instead, add a trigger on Lambda edit page.

Ingest Errors

Errors that occur during ingest will end up in the dead letter processing queue, where they are processed by the stac-server-<stage>-failed-ingest Lambda function. Currently all the failed-ingest Lambda does is log the error, see the CloudWatch log /aws/lambda/stac-server-<stage>-failed-ingest for errors.

Development

Install NVM to manage your Node.js environment.

# uses version in .nvmrc
nvm install
nvm use

The package-lock.json was built with npm 8.5.0, so use at least this version.

There are several useful npm commands available to use locally:

# Install dependencies in package.json
npm install

# Run the build command in each of the packages (runs webpack)
npm run build

# Run ESLint
npm run lint

# To run tests for all packages
npm run test

# To build API docs from the api spec
npm run build-api-docs # TODO: this fails

Running Locally

Before the API can be run, Elasticsearch and Localstack need to be running. There is a docker-compose.yml file to simplify running Elasticsearch locally:

docker-compose up -d

The API can then be run with:

npm run serve

Connect to the server on http://localhost:3000/

Other configurations can be passed as shell environment variables, e.g.,

export ENABLE_TRANSACTIONS_EXTENSION=true
export ES_HOST='https://search-stac-server-dev-es-7awl6h344qlpvly.us-west-2.es.amazonaws.com'
npm run serve

Running Tests

stac-server uses ava to execute tests.

# alias to run unit tests
npm test

# run unit tests in tests directory
npm run test:unit

# run unit tests with coverage
npm run test:coverage

# run tests from a single test file whose titles match 'foobar*'
npx ava tests/test_es.js --match='foobar*'

System and Integration Tests

The System and Integration tests use an Elasticsearch server running in Docker and a local instance of the API.

When the system tests run, they:

  1. Wait for Elasticsearch to be available
  2. Delete all indices from Elasticsearch
  3. Start an instance of the API. That API will be available at http://localhost:3000/dev/
  4. Wait for the API to be available
  5. Run the integration tests in ./tests/system/test_*.js
  6. Stop the API

Before running the system tests, make sure to start Elasticsearch using:

docker-compose up -d

Running these tests requires the timeout utility is installed. On Linux, this is probably already installed, and on macOS it can be installed with brew install coreutils.

Once Elasticsearch has been started, run the system tests:

npm run test:system

Run the integration tests (Note: currently none exist):

npm run test:integration

About

stac-server was forked from sat-api. Stac-server is for STAC versions 0.9.0+, while sat-api exists for versions of STAC prior to 0.9.0.

stac-server's People

Contributors

atdaniel avatar dependabot[bot] avatar drewbo avatar fredliporace avatar j08lue avatar kbgg avatar matthewhanson avatar metasim avatar peteshepley avatar philvarner avatar quetcodesfire avatar samsipe avatar sharkinsspatial avatar vincentsarago avatar

Watchers

 avatar

Forkers

jeff-burchett

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.