Skip to content

Bug: Injecting Lambda context into logger causing exception #4362

Closed
@Thomas-McKanna

Description

@Thomas-McKanna

Expected Behaviour

Should be able to write a Lambda handler like this:

@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP, log_event=True)
@tracer.capture_lambda_handler
def lambda_handler(request: dict, context: LambdaContext) -> dict:
    return app.resolve(request, context)

Current Behaviour

502 errors are being returned by API endpoint pointing to Lambda function. Error log is:

[ERROR] AttributeError: 'NoneType' object has no attribute 'append_keys'
Traceback (most recent call last):
  File "/var/task/aws_lambda_powertools/logging/logger.py", line 455, in decorate
    self.append_keys(cold_start=cold_start, **lambda_context.__dict__)
  File "/var/task/aws_lambda_powertools/logging/logger.py", line 603, in append_keys
    self.registered_formatter.append_keys(**additional_keys)

I suspect this error is due to a recent change, as things were working for me yesterday. Removing the @logger.inject_lambda_context decorator removed the error.

The code does not work in version 2.38.0, but does work in version 2.37.0 and earlier.

Code snippet

@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP, log_event=True)
@tracer.capture_lambda_handler
def lambda_handler(request: dict, context: LambdaContext) -> dict:
    return app.resolve(request, context)

Possible Solution

No response

Steps to Reproduce

Make minimalistic Lambda Powertools event handler.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

Lambda Layers

Debugging logs

No response

Metadata

Metadata

Labels

bugSomething isn't workinglogger

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions