Crates.io | aws-lambda-log-proxy |
lib.rs | aws-lambda-log-proxy |
version | 0.4.0 |
source | src |
created_at | 2024-04-02 15:40:56.960641 |
updated_at | 2024-10-16 06:01:16.301419 |
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 | 63,866 |
Filter / transform / forward 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.
cargo add aws-lambda-log-proxy
See examples for more details.
A real world case: AWS Lambda Log Filter.
We need a solution to realize the following features without modifying the code of your existing AWS Lambda functions:
You need a wrapper script to start the handler process (with the _LAMBDA_TELEMETRY_LOG_FD
environment variable removed) and pipe the logs to the proxy. The proxy will filter / transform / forward the logs before they are sent to CloudWatch Logs.
We use AWS Lambda Runtime Proxy to intercept AWS Lambda runtime API requests so we can suppress the invocation/next
request to process logs as much as possible. You need to override the AWS_LAMBDA_RUNTIME_API
environment variable for your handler function to point to the runtime proxy in the wrapper script.
Actually you could just create a shell scripts with the content env -u _LAMBDA_TELEMETRY_LOG_FD "$@" 2>&1 | grep --line-buffered xxx
and use a wrapper script to realize a simple filter. However we need this lib to realize the following features:
invocation/next
request to process logs as much as possible. This is very important if you want to stream the logs to external services in real time.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.