Crates.io | aws-lambda-log-proxy |
lib.rs | aws-lambda-log-proxy |
version | 0.3.0 |
source | src |
created_at | 2024-04-02 15:40:56.960641 |
updated_at | 2024-05-22 07:03:14.894868 |
description | Filter or transform logs from AWS Lambda functions before they are sent to CloudWatch Logs. |
homepage | |
repository | https://github.com/DiscreteTom/aws-lambda-log-proxy |
max_upload_size | |
id | 1193666 |
size | 59,190 |
Filter or transform logs from AWS Lambda functions before they are sent to CloudWatch Logs.
[!NOTE] This is a library for developers. If you are looking for a binary executable, see AWS Lambda Log Filter.
[!CAUTION] Possible data loss if you write tons of logs and return immediately. See possible data loss below.
Add the following to the dependencies
in your Cargo.toml
:
aws-lambda-log-proxy = "0.2"
or run:
cargo add aws-lambda-log-proxy
A real world case: AWS Lambda Log Filter.
We need a solution to realize the following features without modifying the existing code of AWS Lambda functions:
We use AWS Lambda Runtime Proxy to spawn the handler process as a child process of the proxy (and optionally disable the _LAMBDA_TELEMETRY_LOG_FD
environment variable) to intercept the logs, then suppress the invocation/next
request to process logs as much as possible.
Actually you could just create a shell scripts with the content exec "$@" 2>&1 | grep --line-buffered xxx
and use the lambda runtime wrapper script to realize a simple filter. However we need this lib to realize the following features:
_LAMBDA_TELEMETRY_LOG_FD
environment variable to ensure the logs are printed to the stdout/stderr instead of the telemetry log file.invocation/next
request to process logs as much as possible.Though we tried our best to suppress the invocation/next
request to process logs as much as possible, if you write tons of logs (more than thousands of lines) and return immediately, there might be some logs not processed.
As a best practice, it is your responsibility to do a thorough benchmark test against your own use case to ensure the logs are processed as expected.