Skip to content

Commit

Permalink
Merge branch 'main' of github.com:epilot-dev/aws-lambda-utility-middl…
Browse files Browse the repository at this point in the history
…ewares
  • Loading branch information
João Pinho committed Dec 26, 2023
2 parents 9fd01d6 + 4e6297a commit c1019f3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/large-response-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@

Enables Lambdas to return responses larger than 6MB by offloading the content to S3 and returning a reference to the S3 file.

![](../../docs/out/architecture-1/Architecture%20-%20Sequence%20Diagram.svg)
<p align="center">
<img src="./docs/out/architecture-1/Architecture%20-%20Sequence%20Diagram.svg" />
</p>

When a client can handle a Large Response, it must send a request with the HTTP Header Accept: application/large-response.vnd+json. The application/large-response.vnd+json is a custom MIME type indicating that the client agrees to receive a large response payload when necessary. The response body for the large-response.vnd+json MIME type is in the following format:
When a client can handle a Large Response, it must send a request with the HTTP Header `Accept: application/large-response.vnd+json`. The `application/large-response.vnd+json` is a custom MIME type indicating that the client agrees to receive a large response payload when necessary. The response body for the `large-response.vnd+json` MIME type is in the following format:

```json
{
"$payload_ref": "http://<s3 file reference link>"
}
```

If the client provides the large response MIME type, the Lambda will not log an error using Log.error. Instead, it will rewrite the original response with a reference to the offloaded large payload. Furthermore, the rewritten response will include the HTTP header Content-Type with the value application/large-response.vnd+json.
If the client provides the large response MIME type, the Lambda will not log an error using `Log.error`. Instead, it will rewrite the original response with a reference to the offloaded large payload. Furthermore, the rewritten response will include the HTTP header `Content-Type` with the value `application/large-response.vnd+json`.

If the client does not provide the large response MIME type, the Lambda will log an error with Log.error, and the response will fail due to an excessively large response body.
If the client does not provide the large response MIME type, the Lambda will log an error with `Log.error`, and the response will fail due to an excessively large response body.

### Middleware Configuration:

Supported Parameters:

| Parameter | Type | Description |
| --------------- | ----------------- | ---------------------------------------------------------------------------- |
| thresholdWarn | number | Warning threshold level (percentage of `sizeLimitInMB`), e.g: 0.80 |
| thresholdError | number | Error threshold level (percentage of `sizeLimitInMB`), e.g: 0.90 |
| sizeLimitInMB | number | Maximum allowed size limit in MB, e.g 6 |
| outputBucket | string | Identifier or name of the output S3 bucket |
| groupRequestsBy | function - mapper | Function to group requests, based on API Gateway event V2. Defaults to 'all' |
| thresholdWarn | `number` | Warning threshold level (percentage of `sizeLimitInMB`), e.g: 0.80 |
| thresholdError | `number` | Error threshold level (percentage of `sizeLimitInMB`), e.g: 0.90 |
| sizeLimitInMB | `number` | Maximum allowed size limit in MB, e.g 6 |
| outputBucket | `string` | Identifier or name of the output S3 bucket |
| groupRequestsBy | `function - mapper` | Function to group requests, based on API Gateway event V2. Defaults to 'all' |

Example Usage:

Expand Down

0 comments on commit c1019f3

Please sign in to comment.