aws-lambda-log-proxy 0.1.1

Filter or transform logs from AWS Lambda functions before they are sent to CloudWatch Logs.
Documentation

AWS Lambda Log Proxy

Crates.io Version license

log-flow

Filter or transform logs from AWS Lambda functions before they are sent to CloudWatch Logs.

Usage

Installation

Add the following to the dependencies in your Cargo.toml:

aws-lambda-log-proxy = "0.1"

or run:

cargo add aws-lambda-log-proxy

Examples

A real world case: AWS Lambda Log Filter.

Documentation

Why We Need This?

We need a solution to realize the following features without modifying the existing code of AWS Lambda functions:

  • Reduce the volume of logs to lower the costs.
  • Wrap existing logs in JSON with customizable level and field name, so we can use the built-in Lambda Log-Level Filtering to filter them.
  • But keep the EMF logs untouched so we can still retrieve the metrics.

How It Works?

We use AWS Lambda Runtime Proxy to spawn the handler process as a child process of the proxy to intercept the logs, then suppress the invocation/next request until all logs are processed.

Performance

The processing of logs is done in a separate process asynchronously, so it won't block the main handler process. Besides, we only suppress the invocation/next request but not the invocation/response request, so the synchronous invocator like AWS API Gateway won't be blocked by the processing of logs.

However, if you do something cpu-intensive in the log processing, it may still affect the performance of the main handler process, since the proxy process and the handler process share the same CPU and memory resources. Increase the memory of the Lambda function may help in this case.

CHANGELOG