AWS Logging Handlers is a Python library that provides multithreaded logging handlers for streaming log records to Amazon S3 and Kinesis Data Streams. It leverages asynchronous uploading with multiple worker threads and supports gzip compression for S3 logs. The library is actively maintained, with version 2.0.5 currently available, and receives regular minor updates for improvements and bug fixes.
pip install aws-logging-handlersVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure both `S3Handler` and `KinesisHandler` to stream log records to their respective AWS services. It shows how to set a formatter, add handlers to a logger, and crucially, how to call `logging.shutdown()` for graceful termination and log flushing. Ensure AWS credentials (e.g., via environment variables or IAM roles) and the specified S3 bucket and Kinesis stream exist and are correctly configured.
Update import statements to use capitalized submodule names (e.g., `from aws_logging_handlers.S3 import S3Handler` instead of `from aws_logging_handlers.s3 import S3Handler`). Review the latest documentation for handler constructor arguments.
Always call `logging.shutdown()` at the end of your application's lifecycle to ensure all buffered logs are flushed to S3 or Kinesis and worker threads terminate gracefully.
Ensure the target S3 bucket and Kinesis stream are pre-provisioned in AWS. Verify that the IAM user/role associated with your application has `s3:PutObject`, `kinesis:PutRecord`, and `kinesis:PutRecords` permissions (among others as needed for specific configurations) for the target resources.
Update your import statements: change `from aws_logging_handlers.s3 import S3Handler` to `from aws_logging_handlers.S3 import S3Handler`. Apply similar changes for `KinesisHandler`.
Verify your AWS credentials and IAM permissions. Ensure environment variables like `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_REGION` are correctly set and not expired. If using an IAM role, confirm it has policies allowing `s3:PutObject` for the target S3 bucket and `kinesis:PutRecord`/`kinesis:PutRecords` for the target Kinesis stream.
1. Ensure `logging.shutdown()` is called at the application's exit. 2. Increase the `workers` parameter for `S3Handler` or `KinesisHandler` if dealing with high log volumes. 3. Check network connectivity to AWS. 4. Double-check that `bucket_name`, `stream_name`, and `session_kwargs={'region_name': ...}` are accurate and match your AWS setup.