Skip to content

Commit ac22122

Browse files
author
Marc
authored
Add pre- and post-hooks (#271)
1 parent 3f77062 commit ac22122

File tree

15 files changed

+829
-117
lines changed

15 files changed

+829
-117
lines changed

.markdownlint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"line-length": false
2+
"no-duplicate-heading":
3+
siblings_only: true

CHANGELOG.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
## [0.5.0] - 2022-06-07
8+
## [Unreleased]
99

1010
### Added
1111

1212
- Added mappings for 'id' and 'collection' for default sort keys
13-
14-
## [0.5.0] - 2022-06-01
13+
- Added STAC_API_VERSION as an environment variable to the serverless.yml file
14+
- Added STAC_API_VERSION to display on the API landing page within the api.js file under src/lib/api.js in the collectionsToCatalogLinks function
15+
- Add support for pre- and post-hooks
1516

1617
### Changed
1718

1819
- Modified sortby and collections parameters in nextlink
19-
20-
## [0.5.0] - 2022-05-20
21-
22-
### Changed
23-
2420
- Used map instead of foreach/push in api.js file
25-
26-
## [0.5.0] - 2022-05-18
27-
28-
### Added
29-
30-
- Added STAC_API_VERSION as an environment variable to the serverless.yml file
31-
- Added STAC_API_VERSION to display on the API landing page within the api.js file
32-
under src/lib/api.js in the collectionsToCatalogLinks function
33-
34-
### Changed
35-
3621
- Changed the rel type to 'server' for the URL to the STAC API webpage inside the Links object
22+
- Modified sortby and collections parameters in nextlink
23+
- Used map instead of foreach/push in api.js file
24+
- Compression of responses is now handled by API Gateway and not Express. This means that the _uncompressed_ response from stac-server [must be less than 6 MB](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#function-configuration-deployment-and-execution).
3725

3826
### Removed
3927

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Ingesting large items](#ingesting-large-items)
2020
- [Subscribing to SNS Topics](#subscribing-to-sns-topics)
2121
- [Ingest Errors](#ingest-errors)
22+
- [Pre- and Post- Hooks](#pre--and-post-hooks)
2223
- [Development](#development)
2324
- [Running Locally](#running-locally)
2425
- [Running Unit Tests](#running-unit-tests)
@@ -381,6 +382,51 @@ Stac-server can also be subscribed to SNS Topics that publish complete STAC Item
381382

382383
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.
383384

385+
## Pre- and Post-Hooks
386+
387+
Stac-server supports two hooks into the request process: a pre-hook and a post-hook. These are each lambda functions which, if configured, will be invoked by stac-server. It is assumed that the stac-server lambda has been granted permission to invoke these lambda functions, if configured.
388+
389+
### Pre-Hook
390+
391+
If the stac-server is deployed with the `PRE_HOOK` environment variable set to the name of a lambda function, then that function will be called as the pre-hook.
392+
393+
The event passed into the pre-hook lambda will be an instance of an [API Gateway Proxy Event](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format).
394+
395+
If the return value from the pre-hook lambda is an instance of an [API Gateway Proxy Result](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format), then that response will immediately be returned to the client.
396+
397+
If the return value of the pre-hook lambda is an instance of an [API Gateway Proxy Event](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format), then that event will be passed along to stac-server.
398+
399+
If the pre-hook lambda throws an exception, an internal server error will be returned to the client.
400+
401+
### Post-Hook
402+
403+
If the stac-server is deployed with the `POST_HOOK` environment variable set to the name of a lambda function, then that function will be called as the post-hook.
404+
405+
The event passed into the post-hook labmda will be the response from the stac-server, and will be an instance of an [API Gateway Proxy Result](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format).
406+
407+
The return value of the post-hook lambda must be an instance of an [API Gateway Proxy Result](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format).
408+
409+
If the post-hook lambda throws an exception, an internal server error will be returned to the client.
410+
411+
### Request Flow
412+
413+
```mermaid
414+
flowchart
415+
client -- APIGatewayProxyEvent --> pre-hook
416+
pre-hook[pre-hook lambda]
417+
pre-hook -- APIGatewayProxyResult --> client
418+
pre-hook -- APIGatewayProxyEvent --> stac-server
419+
post-hook[post-hook lambda]
420+
stac-server -- APIGatewayProxyResult --> post-hook
421+
post-hook -- APIGatewayProxyResult --> client
422+
```
423+
424+
### Notes
425+
426+
Lambda payloads and responses [must be less than 6 MB](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#function-configuration-deployment-and-execution). A larger payload will result in an internal server error being returned to the client.
427+
428+
The outputs of the pre- and post-hooks are validated and, if they don't comply with the defined schemas, an internal server error will be returned to the client. Information about the invalid event, as well as details about the parsing errors, will be logged to CloudWatch.
429+
384430
## Development
385431

386432
Install [NVM](https://github.com/nvm-sh/nvm) to manage your Node.js environment.

0 commit comments

Comments
 (0)