|
19 | 19 | - [Ingesting large items](#ingesting-large-items)
|
20 | 20 | - [Subscribing to SNS Topics](#subscribing-to-sns-topics)
|
21 | 21 | - [Ingest Errors](#ingest-errors)
|
| 22 | + - [Pre- and Post- Hooks](#pre--and-post-hooks) |
22 | 23 | - [Development](#development)
|
23 | 24 | - [Running Locally](#running-locally)
|
24 | 25 | - [Running Unit Tests](#running-unit-tests)
|
@@ -381,6 +382,51 @@ Stac-server can also be subscribed to SNS Topics that publish complete STAC Item
|
381 | 382 |
|
382 | 383 | 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.
|
383 | 384 |
|
| 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 | + |
384 | 430 | ## Development
|
385 | 431 |
|
386 | 432 | Install [NVM](https://github.com/nvm-sh/nvm) to manage your Node.js environment.
|
|
0 commit comments