Skip to content

AWS CloudWatch

CloudWatchSink sends log records to AWS CloudWatch Logs with batching and background flushing. Automatically creates log groups and streams.

Installation

This integration requires the boto3 package.

bash
uv add logly[aws]
bash
pip install "logly[aws]"
bash
uv add boto3
bash
pip install boto3

Missing Dependency

If boto3 is not installed, you'll see:

ModuleNotFoundError: No module named 'boto3'

Usage

python
import logging
from logly.integrations.aws_cloudwatch import CloudWatchSink

logger = logging.getLogger("myapp")
logger.addHandler(
    CloudWatchSink(
        log_group="my-app",
        log_stream="main",
    )
)
logger.setLevel(logging.INFO)

Configuration

ParameterDefaultDescription
log_group(required)CloudWatch log group name
log_stream(required)CloudWatch log stream name
regionNoneAWS region (uses boto3 default if not set)
batch_size10000Max events per batch
flush_interval5Seconds between background flushes
create_groupTrueAuto-create log group if missing
create_streamTrueAuto-create log stream if missing

Full Example

python
import logging
from logly.integrations.aws_cloudwatch import CloudWatchSink

logger = logging.getLogger("myapp")
logger.setLevel(logging.DEBUG)

handler = CloudWatchSink(
    log_group="/aws/lambda/my-function",
    log_stream="2024-01-15",
    region="us-east-1",
    batch_size=5000,
    flush_interval=10,
)
logger.addHandler(handler)

logger.info("Lambda invoked")
logger.warning("Rate limit approaching")
logger.error("External API timeout")

Released under the MIT License.