Skip to content

Commit dd18077

Browse files
Merge pull request #8 from geospatial-jeff/dev
Lambda Layers
2 parents 1d6c73d + 2544c15 commit dd18077

36 files changed

+671
-183
lines changed

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM lambci/lambda:build-python3.6
2+
3+
4+
# Installing system libraries
5+
RUN \
6+
yum install -y wget; \
7+
yum install -y geos-devel; \
8+
yum clean all; \
9+
yum autoremove;
10+
11+
12+
# Paths
13+
ENV \
14+
PREFIX=/usr/local \
15+
LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
16+
17+
# Switch to build directory
18+
WORKDIR /build
19+
20+
# Installing cognition-datasources + requirements
21+
COPY requirements-dev.txt ./
22+
23+
RUN \
24+
pip install -r requirements-dev.txt; \
25+
pip install git+https://github.com/geospatial-jeff/cognition-datasources.git
26+
27+
28+
29+
# Copy shell scripts
30+
COPY bin/* /usr/local/bin/
31+
32+
WORKDIR /home/cognition-datasources

MANIFEST.in

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,47 @@
1-
# cognition-datasources
2-
31
## About
4-
This library defines a STAC-compliant standardized interface for searching geospatial assets, primarily remotely sensed imagery. The [Spatio-Temporal-Asset-Catalog (STAC)](https://github.com/radiantearth/stac-spec) specification provides common metadata and API schemas to search and access geospatial data. The standardized interface used by the library is based on the STAC spec and allows searching across three dimensions:
5-
6-
- **Spatial:** Find all assets which intersect a bounding box.
7-
- **Temporal:** Find all assets acquired within a temporal window.
8-
- **Properties:** Find all assets with certain metadata.
92

10-
Not all commonly used datasources are currently STAC-compliant. In such cases, the library maintains a standardized search interface by wrapping the API with a STAC-compatible API which parses the initial search parameters into a format compatible with the underlying API. A request to the API is sent and the response is parsed into a STAC Item and returned to the user. The table below of supported datasources states which are STAC-compliant.
3+
This library defines a pluggable, STAC-compliant, service for searching geospatial assets, primarily remotely sensed imagery, and serves two primary purposes:
114

12-
![title](docs/images/api-diagram.png)
5+
1. Define a pluggable driver interface (similar to GraphQL resolvers) for wrapping the STAC spec around legacy datasources.
6+
2. Provide a framework for loading / executing drivers both locally and in the cloud.
137

14-
#### Datasource Drivers
15-
The interface defined by the library is extended by datasource drivers which are defined in external github repositories and loaded into the library through a command line interface. Similar to how drivers control hardware, the logic implemented in the datasource driver influences how cognition-datasources accesses the underlying datasource. Each driver is expected to follow a specific pattern and pass a standard set of test cases (enforced with CircleCI). Check out the [contribution guidelines](/docs/contributing.md) for a guide on how to develop your own datasource driver!
8+
Each driver translates the STAC-compliant request into a format compatible with the underlying API while translating the API response to a valid STAC Item. Drivers are packaged and deployed to AWS Lambda and a single API Gateway endpoint is created which allows searching the loaded datasources. The goal is to create an extensible service which allows users to integrate their datasets with the STAC ecosystem without having to change how their data is stored and queried.
169

10+
![title](docs/images/service-diagram.png?style=centerme)
1711

18-
## Setup
12+
## Installation
1913
```
20-
# Install library
21-
pip install git+https://github.com/geospatial-jeff/cognition-datasources
22-
23-
# Load datasources
24-
cognition-datasources load -d Landsat8 -d Sentinel2
14+
git clone https://github.com/geospatial-jeff/cognition-datasources
15+
cd cognition-datasources
16+
python setup.py develop
2517
```
2618

27-
## Usage
28-
29-
#### Python
30-
```python
31-
from datasources import Manifest
32-
33-
# Create manifest
34-
manifest = Manifest()
19+
## Deployment
20+
```
21+
# Load datasources
22+
cognition-datasources -d Landsat8 -d Sentinel2 -d SRTM -d NAIP
3523
36-
# Search arguments
37-
spatial = {"type": "Polygon", "coordinates": [[...]]}
38-
temporal = ("2018-10-30", "2018-12-31")
39-
properties = {'eo:cloud_cover': {'lt': 10}}
24+
# Build docker container
25+
docker build . -t cognition-datasources:latest
4026
41-
# Create searches for Landsat8 and Sentinel2
42-
manifest['Landsat8'].search(spatial, temporal=temporal, properties=properties)
43-
manifest['Sentinel2'].search(spatial, temporal=temporal, properties=properties)
27+
# Package service
28+
docker run --rm -v $PWD:/home/cognition-datasources -it cognition-datasources:latest package-service.sh
4429
45-
# Execute searches
46-
response = manifest.execute()
30+
# Deploy to AWS
31+
sls deploy -v
4732
```
33+
Read the [deployment docs](./docs/deployment.md) for more information on deployment.
4834

49-
#### CLI
50-
```
51-
cognition-datasources search xmin ymin xmax ymax --start-date "2018-10-30" --end-date "2018-12-31" -d Landsat8 -d Sentinel2 --output response.json
52-
```
35+
## Usage
36+
The deployment generates an AWS API Gateway endpoint which supports STAC-compliant searches of the loaded datasources through the `/stac/search` endpoint (POST). Read the [API docs](./docs/README.md) for usage details.
37+
38+
A live example lives [here](https://github.com/geospatial-jeff/cognition-datasources-api).
5339

5440
## Testing
55-
Each driver must pass a [standard set of test cases](datasources/tests.py) and uses CircleCI to ensure only working drivers are loaded into the library. View the status of each driver [here](/docs/datasource-status.md).
41+
Each driver must pass a [standard set of test cases](./datasources/tests.py) and uses CircleCI to ensure only working drivers are loaded into the library. View the status of each driver [here](./docs/datasource-status.md).
5642

57-
## Documentation
58-
Read the [quickstart](./docs/quickstart.ipynb) and [documentation](./docs).
43+
## Contributing
44+
Check out the [contributing docs](./docs/contributing.md) for step-by-step guide for building your own driver.
5945

6046
## Supported Datasource Drivers
6147
| Name | Source | STAC-Compliant | Notes |
@@ -69,4 +55,4 @@ Read the [quickstart](./docs/quickstart.ipynb) and [documentation](./docs).
6955
| [Sentinel2](https://github.com/geospatial-jeff/cognition-datasources-sentinel2) | [AWS Earth: Sentinel2](https://registry.opendata.aws/sentinel-2/) | True | Sends requests to [sat-api](https://github.com/sat-utils/sat-api). |
7056
| [SRTM](https://github.com/geospatial-jeff/cognition-datasources-srtm) | [AWS: Terrain Tiles](https://registry.opendata.aws/terrain-tiles/) | False | Does not send any requests. |
7157
| [USGS 3DEP](https://github.com/geospatial-jeff/cognition-datasources-usgs3dep) | [AWS: USGS 3DEP](https://registry.opendata.aws/usgs-lidar/) | False | Sends request to AWS S3 Bucket. |
72-
| [Microsoft Building Footprints](https://github.com/geospatial-jeff/cognition-datasources-mbf) | [Microsoft](https://github.com/Microsoft/USBuildingFootprints) / [ESRI](https://www.arcgis.com/home/item.html?id=f40326b0dea54330ae39584012807126) | False | Sends requests to ESRI Feature Layer |
58+
| [Microsoft Building Footprints](https://github.com/geospatial-jeff/cognition-datasources-mbf) | [Microsoft](https://github.com/Microsoft/USBuildingFootprints) / [ESRI](https://www.arcgis.com/home/item.html?id=f40326b0dea54330ae39584012807126) | False | Sends requests to ESRI Feature Layer |

bin/package-layer.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Directory used for deployment
4+
export DEPLOY_DIR=layer
5+
6+
mkdir $DEPLOY_DIR
7+
8+
PYPATH=/var/lang/lib/python3.6/site-packages
9+
10+
11+
echo Creating deployment package for cognition-datasources
12+
13+
# Moving python libraries
14+
mkdir $DEPLOY_DIR/python
15+
EXCLUDE="shapely* stac_validator* s3transfer* boto3* botocore* pip* docutils* *.pyc setuptools* wheel* coverage* testfixtures* mock* *.egg-info *.dist-info __pycache__ easy_install.py"
16+
17+
EXCLUDES=()
18+
for E in ${EXCLUDE}
19+
do
20+
EXCLUDES+=("--exclude ${E} ")
21+
done
22+
23+
rsync -ax $PYPATH/ $DEPLOY_DIR/python/ ${EXCLUDES[@]}
24+
25+
cd $DEPLOY_DIR
26+
zip -ruq ../lambda-layer.zip ./

bin/package-service.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# Directory used for deployment
4+
export DEPLOY_DIR=service
5+
6+
mkdir $DEPLOY_DIR
7+
8+
# Moving handler
9+
cp handler.py $DEPLOY_DIR
10+
11+
cd $DEPLOY_DIR
12+
zip -ruq ../lambda-service-package.zip ./

datasources/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .manifest import Manifest
33

44

5+
layer_arn = 'arn:aws:lambda:us-east-1:725820063953:layer:cognition-datasources:6'

0 commit comments

Comments
 (0)