From e5381ae60e42b910f6a1d19d93699b89917bffa8 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Thu, 6 May 2021 11:42:28 -0700 Subject: [PATCH 1/5] fix(docs): Use updated names for ProxyEventType (#424) --- docs/core/event_handler/api_gateway.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/event_handler/api_gateway.md b/docs/core/event_handler/api_gateway.md index c3c449338b5..43d056f3abd 100644 --- a/docs/core/event_handler/api_gateway.md +++ b/docs/core/event_handler/api_gateway.md @@ -208,7 +208,7 @@ When using API Gateway HTTP API to front your Lambda functions, you can instruct tracer = Tracer() logger = Logger() - app = ApiGatewayResolver(proxy_type=ProxyEventType.http_api_v2) + app = ApiGatewayResolver(proxy_type=ProxyEventType.APIGatewayProxyEventV2) @app.get("/hello") @tracer.capture_method @@ -235,7 +235,7 @@ When using ALB to front your Lambda functions, you can instruct `ApiGatewayResol tracer = Tracer() logger = Logger() - app = ApiGatewayResolver(proxy_type=ProxyEventType.alb_event) + app = ApiGatewayResolver(proxy_type=ProxyEventType.ALBEvent) @app.get("/hello") @tracer.capture_method From 054f64cfe81d32c8072f996b79e4055c42705fd5 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 7 May 2021 14:59:49 +1000 Subject: [PATCH 2/5] Support .info("foo %s", "bar") formatting in logger (#426) --- aws_lambda_powertools/logging/formatter.py | 3 +++ .../functional/test_logger_powertools_formatter.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/aws_lambda_powertools/logging/formatter.py b/aws_lambda_powertools/logging/formatter.py index 47418063732..7ff9881062a 100644 --- a/aws_lambda_powertools/logging/formatter.py +++ b/aws_lambda_powertools/logging/formatter.py @@ -176,6 +176,9 @@ def _extract_log_message(self, log_record: logging.LogRecord) -> Union[Dict[str, if isinstance(message, dict): return message + if log_record.args: # logger.info("foo %s", "bar") requires formatting + return log_record.getMessage() + if isinstance(message, str): # could be a JSON string try: message = self.json_deserializer(message) diff --git a/tests/functional/test_logger_powertools_formatter.py b/tests/functional/test_logger_powertools_formatter.py index 4b92e6b47b9..c9f970e29a5 100644 --- a/tests/functional/test_logger_powertools_formatter.py +++ b/tests/functional/test_logger_powertools_formatter.py @@ -275,3 +275,16 @@ def test_logging_various_primitives(stdout, service_name, message): # THEN it should raise no serialization/deserialization error logger.info(message) json.loads(stdout.getvalue()) + + +def test_log_formatting(stdout, service_name): + # GIVEN a logger with default settings + logger = Logger(service=service_name, stream=stdout) + + # WHEN logging a message with formatting + logger.info('["foo %s %d %s", null]', "bar", 123, [1, None]) + + log_dict: dict = json.loads(stdout.getvalue()) + + # THEN the formatting should be applied (NB. this is valid json, but hasn't be parsed) + assert log_dict["message"] == '["foo bar 123 [1, None]", null]' From e08e7f91bcceb95aedfdfc00fac4371ff323e583 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 7 May 2021 12:21:58 +0200 Subject: [PATCH 3/5] docs: update list of features --- README.md | 24 +++++++++++++----------- docs/index.md | 25 +++++++++++++------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 95c87f929c4..b452dd37d1a 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,19 @@ A suite of Python utilities for AWS Lambda functions to ease adopting best pract ## Features -* **[Tracing](https://awslabs.github.io/aws-lambda-powertools-python/core/tracer/)** - Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions -* **[Logging](https://awslabs.github.io/aws-lambda-powertools-python/core/logger/)** - Structured logging made easier, and decorator to enrich structured logging with key Lambda context details -* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-python/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) -* **[Bring your own middleware](https://awslabs.github.io/aws-lambda-powertools-python/utilities/middleware_factory/)** - Decorator factory to create your own middleware to run logic before, and after each Lambda invocation -* **[Parameters utility](https://awslabs.github.io/aws-lambda-powertools-python/utilities/parameters/)** - Retrieve and cache parameter values from Parameter Store, Secrets Manager, or DynamoDB -* **[Batch processing](https://awslabs.github.io/aws-lambda-powertools-python/utilities/batch/)** - Handle partial failures for AWS SQS batch processing -* **[Typing](https://awslabs.github.io/aws-lambda-powertools-python/utilities/typing/)** - Static typing classes to speedup development in your IDE -* **[Validation](https://awslabs.github.io/aws-lambda-powertools-python/utilities/validation/)** - JSON Schema validator for inbound events and responses -* **[Event source data classes](https://awslabs.github.io/aws-lambda-powertools-python/utilities/data_classes/)** - Data classes describing the schema of common Lambda event triggers -* **[Parser](https://awslabs.github.io/aws-lambda-powertools-python/utilities/parser/)** - Data parsing and deep validation using Pydantic -* **[Idempotency](https://awslabs.github.io/aws-lambda-powertools-python/utilities/idempotency/)** - Convert your Lambda functions into idempotent operations which are safe to retry +* **[Tracing](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/tracer/)** - Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions +* **[Logging](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/logger/)** - Structured logging made easier, and decorator to enrich structured logging with key Lambda context details +* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) +* **[Event handler: AppSync](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/appsync/)** - AWS AppSync event handler for Lambda Direct Resolver and Amplify GraphQL Transformer function +* **[Event handler: API Gateway and ALB](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/)** - Amazon API Gateway REST/HTTP API and ALB event handler for Lambda functions invoked using Proxy integration +* **[Bring your own middleware](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/middleware_factory/)** - Decorator factory to create your own middleware to run logic before, and after each Lambda invocation +* **[Parameters utility](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/parameters/)** - Retrieve and cache parameter values from Parameter Store, Secrets Manager, or DynamoDB +* **[Batch processing](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/batch/)** - Handle partial failures for AWS SQS batch processing +* **[Typing](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/typing/)** - Static typing classes to speedup development in your IDE +* **[Validation](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/validation/)** - JSON Schema validator for inbound events and responses +* **[Event source data classes](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/data_classes/)** - Data classes describing the schema of common Lambda event triggers +* **[Parser](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/parser/)** - Data parsing and deep validation using Pydantic +* **[Idempotency](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/idempotency/)** - Convert your Lambda functions into idempotent operations which are safe to retry ### Installation diff --git a/docs/index.md b/docs/index.md index bb3d4925c21..9edb82f4716 100644 --- a/docs/index.md +++ b/docs/index.md @@ -141,18 +141,19 @@ aws serverlessrepo list-application-versions \ | Utility | Description | ------------------------------------------------- | --------------------------------------------------------------------------------- -| [Tracing](./core/tracer.md) | Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions -| [Logger](./core/logger.md) | Structured logging made easier, and decorator to enrich structured logging with key Lambda context details -| [Metrics](./core/metrics.md) | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) -| [Event handler - AppSync](./core/event_handler/appsync.md) | AppSync event handler for Lambda Direct Resolver and Amplify GraphQL Transformer function -| [Middleware factory](./utilities/middleware_factory.md) | Decorator factory to create your own middleware to run logic before, and after each Lambda invocation -| [Parameters](./utilities/parameters.md) | Retrieve parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, or Amazon DynamoDB, and cache them for a specific amount of time -| [Batch processing](./utilities/batch.md) | Handle partial failures for AWS SQS batch processing -| [Typing](./utilities/typing.md) | Static typing classes to speedup development in your IDE -| [Validation](./utilities/validation.md) | JSON Schema validator for inbound events and responses -| [Event source data classes](./utilities/data_classes.md) | Data classes describing the schema of common Lambda event triggers -| [Parser](./utilities/parser.md) | Data parsing and deep validation using Pydantic -| [Idempotency](./utilities/idempotency.md) | Idempotent Lambda handler +[Tracing](./core/tracer.md) | Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions +[Logger](./core/logger.md) | Structured logging made easier, and decorator to enrich structured logging with key Lambda context details +[Metrics](./core/metrics.md) | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) +[Event handler: AppSync](./core/event_handler/appsync.md) | AppSync event handler for Lambda Direct Resolver and Amplify GraphQL Transformer function +[Event handler: API Gateway and ALB](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/) | Amazon API Gateway REST/HTTP API and ALB event handler for Lambda functions invoked using Proxy integration +[Middleware factory](./utilities/middleware_factory.md) | Decorator factory to create your own middleware to run logic before, and after each Lambda invocation +[Parameters](./utilities/parameters.md) | Retrieve parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, or Amazon DynamoDB, and cache them for a specific amount of time +[Batch processing](./utilities/batch.md) | Handle partial failures for AWS SQS batch processing +[Typing](./utilities/typing.md) | Static typing classes to speedup development in your IDE +[Validation](./utilities/validation.md) | JSON Schema validator for inbound events and responses +[Event source data classes](./utilities/data_classes.md) | Data classes describing the schema of common Lambda event triggers +[Parser](./utilities/parser.md) | Data parsing and deep validation using Pydantic +[Idempotency](./utilities/idempotency.md) | Idempotent Lambda handler ## Environment variables From b77d7a31b47307fe8294608a4e151abef980ac3b Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 7 May 2021 19:40:55 +0200 Subject: [PATCH 4/5] docs(event_handler): add missing note on trimmed responses --- docs/core/event_handler/api_gateway.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/event_handler/api_gateway.md b/docs/core/event_handler/api_gateway.md index 43d056f3abd..87263062f4f 100644 --- a/docs/core/event_handler/api_gateway.md +++ b/docs/core/event_handler/api_gateway.md @@ -89,7 +89,7 @@ You can define your functions to match a path and HTTP method, when you use the Here's an example where we have two separate functions to resolve two paths: `/hello`. -!!! info "We automatically serialize `Dict` responses as JSON and set content-type to `application/json`" +!!! info "We automatically serialize `Dict` responses as JSON, trim whitespaces for compact responses, and set content-type to `application/json`" === "app.py" From 93fad02683c8d2ab08127343c27b8084f2e6f1cf Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 13 May 2021 13:32:58 +0200 Subject: [PATCH 5/5] chore: bump to 1.15.1 --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d25fc22a0a..1f27a3cc5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,15 @@ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) fo + ## [Unreleased] +## [1.15.1] - 2021-05-13 + +### Fixed + +* **Logger**: Fix a regression with the `%s` operator + ## [1.15.0] - 2021-05-06 ### Added diff --git a/pyproject.toml b/pyproject.toml index d35e58e5664..acff6195b27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aws_lambda_powertools" -version = "1.15.0" +version = "1.15.1" description = "Python utilities for AWS Lambda functions including but not limited to tracing, logging and custom metric" authors = ["Amazon Web Services"] include = ["aws_lambda_powertools/py.typed"]