Changes
This release adds a number of new features to Logger, Tracer, Validator, and Parameters, a new Lambda Layer with extra packages installed (e.g. parser), and documentation fixes.
Detailed information about these features are at the bottom.
For the next release (1.11.0), we'll be focusing on a new Idempotency utility, import time performance improvements for those not using Tracer utility, and possibly a new Circuit Breaker utility.
This release was made possible by the following contributors:
@am29d, @heitorlessa, @michaelbrewer, @n2N8Z, @risenberg-cyberark and @suud
πNew features and non-breaking changes
- feat: Add AppConfig parameter provider (#236) by @risenberg-cyberark
- feat: support extra parameter in Logger messages (#257) by @heitorlessa
π Minor Changes
- feat: toggle to disable log deduplication locally for pytest live log #262 (#268) by @heitorlessa
- improv: add support for custom lambda handlers with kwargs #242 (#269) by @heitorlessa
- improv: override Tracer auto-capture response/exception via env vars (#259) by @heitorlessa
- feat: support custom formats in JSON Schema validation (#247) by @n2N8Z
π Documentation updates
- docs: fix import (#267) by @suud
- docs: add info about extras layer (#260) by @am29d
- docs: add missing parser models (#254) by @risenberg-cyberark
Internal
- chore: bump to 1.10.0 (#270) by @heitorlessa
- chore: move env names to constant file (#264) by @heitorlessa
- chore: general simplifications and cleanup (#255) by @michaelbrewer
- chore: docs npm high vuln. (#256) by @heitorlessa
Details
Logger
Extra parameter
Logger now supports extra
parameter in the standard logging when logging new messages. You can pass in any dictionary to this new parameter, and its keys and values will be available within the root of the structure - This is ephemeral and keys do not persist with its counterpart structure_logs(append=True, ...)
method.
Excerpt
from aws_lambda_powertools import Logger
logger = Logger(service="payment")
fields = { "request_id": "1123" }
logger.info("Hello", extra=fields)
Log sample
{
"timestamp": "2021-01-12 14:08:12,357",
"level": "INFO",
"location": "collect.handler:1",
"service": "payment",
"sampling_rate": 0.0,
"request_id": "1123", // highlight-line
"message": "Collecting payment"
}
Pytest Live Log support
Pytest Live Log support will output logging records as they are emitted directly into the console with colours.
Since Logger drops duplicate log records as of 1.7.0, you can now explicitly override this protection when running tests locally to make use of Pytest Live Log:
POWERTOOLS_LOG_DEDUPLICATION_DISABLED="1" pytest -o log_cli=1
Tracer
Override auto-capture response and exception
When using Tracer decorators, capture_method
or capture_lambda_handler
, we auto-capture its responses and exceptions, serialize them and inject as tracing metadata to ease troubleshooting.
There are times when serializing objects can cause side effects, for example reading S3 streaming objects if not read before. You can now override this behaviour either by parameter or via env var: POWERTOOLS_TRACER_CAPTURE_RESPONSE
, POWERTOOLS_TRACER_CAPTURE_ERROR
Parameters
AppConfig support
You can now retrieve and cache configuration stored in AppConfig natively - Thanks to Ran from CyberArk.
from aws_lambda_powertools.utilities import parameters
def handler(event, context):
# Retrieve a single configuration, latest version
value: bytes = parameters.get_app_config(name="my_configuration", environment="my_env", application="my_app")
Validator
Custom formats
You can now use formats
parameter to instruct Validator utility how to deal with any custom integer or string - Thanks to @n2N8Z
Custom format snippet in a JSON Schema
{
"lastModifiedTime": {
"format": "int64",
"type": "integer"
}
}
Excerpt ignoring int64 and a positive format instead of failing
from aws_lambda_powertools.utilities.validation import validate
event = {} # some event
schema_with_custom_format = {} # some JSON schema that defines a custom format
custom_format = {
"int64": True, # simply ignore it,
"positive": lambda x: False if x < 0 else True
}
validate(event=event, schema=schema_with_custom_format, formats=custom_format)