okdata-aws
Collection of helpers for working with AWS.
Logging for Lambda
Based on Structlog.
Structured and enriched logging for AWS Lambda functions.
TL;DR:
- Decorate handler with
logging_wrapper - Encrich logs with key/value pairs using
log_add - Time functions with
log_duration - Log exceptions with
log_exception
Usage
Regular Lambda functions
Wrap your Lambda handler with logging_wrapper. Badabing badabom, you're good
to go!
You can set the service name using the logging.init method, or configure it
using the SERVICE_NAME environment variable.
from okdata.aws import logging
from okdata.aws.logging import logging_wrapper
logging.init("my_fantastic_lambda")
@logging_wrapper
def handler(event, context):
if error:
return {
"statusCode": 500,
"body": "Automatically logs bodies from error responses even!",
}
FastAPI applications
Call add_fastapi_logging with the FastAPI application as a parameter
to add the logging middleware.
from okdata.aws.logging import add_fastapi_logging
app = FastAPI()
add_fastapi_logging(app)
Encriching logs
By automagic logs will be enriched with git revisions, cold start y/n call
duration and much more, but to add even more magic you can use log_add and
log_duration.
from okdata.aws.logging import logging_wrapper, log_add, log_duration
@logging_wrapper
def handler(event, context):
log_add(dataset=event["dataset"], foo=context["foo"])
log_duration(
lambda: slow_thinger(event["dataset"]),
"my_slow_thinger"
)
... and so on
def slow_thinger():
sleep(9999999999999999)
Exceptions
Struct log can extract exception info if we log the exception to the special
exc_info
key.
For convenience we catch and log uncaught exceptions using this already.
If you need to process an exception you can use log_exception to log it to the
exc_info key.
from okdata.aws.logging import logging_wrapper, log_exception
@logging_wrapper
def handler(event, context):
try:
thing()
except MyException as e:
log_exception(e)
return { ... }
Metadata
Release files for okdata-aws 7.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| okdata_aws-7.0.0.tar.gz | 7.9 kB | Without provenance | Details for okdata_aws-7.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| okdata_aws-7.0.0-py3-none-any.whl | Python 3 | none | any | Details for okdata_aws-7.0.0-py3-none-any.whl |
Total release size: 14.2 kB
Release files / okdata_aws-7.0.0.tar.gz
| Download URL | okdata_aws-7.0.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdbb6c47356e1d2c414dbbbe6760ccf8b4b6ae0e733549951a6aca0a652bd227
|
|
BLAKE2b-256 checksum How to use checksums |
759d261d5a3a822e0fffaf9cd20509b6ca173defb2052c8811a939ac29a7d163
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / okdata_aws-7.0.0-py3-none-any.whl
| Download URL | okdata_aws-7.0.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00a6c1516d4e403057015619a9338140920988f7416d6a6a16deab662579c59b
|
|
BLAKE2b-256 checksum How to use checksums |
1be1d14e1d0e2570315247512edcc9be3f1b6fbda4f8fe3db808de44106597b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Security for okdata-aws 7.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.