Skip to content

ElasticAPM fails to process the context from authorizer #2313

Open
@brett-fitz

Description

@brett-fitz

Describe the bug:

[ERROR] AttributeError: 'dict' object has no attribute 'aws_request_id'
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/opt/threatintel/service.py", line 45, in <module>
    @handler
  File "/usr/local/lib/python3.12/site-packages/elasticapm/contrib/serverless/aws.py", line 111, in decorated
    with _lambda_transaction(func, name, client, event, context) as sls:
  File "/usr/local/lib/python3.12/site-packages/elasticapm/contrib/serverless/aws.py", line 257, in __enter__
    self.set_metadata_and_context(cold_start)
  File "/usr/local/lib/python3.12/site-packages/elasticapm/contrib/serverless/aws.py", line 313, in set_metadata_and_context
    faas["execution"] = self.context.aws_request_id

Interesting enough, when disabling Elastic APM (commenting out), the function runs successfully and the context does have a valid aws_request_id.

Context: LambdaContext([aws_request_id=056c5ea1-0f46-44e3-bd86-09743a79bafc,log_group_name=/aws/lambda/<REDACTED>,log_stream_name=2025/06/06/[$LATEST]<REDACTED>function_name=<REDACTED>memory_limit_in_mb=256,function_version=$LATEST,invoked_function_arn=arn:aws:lambda:us-east-1:<REDACTED>:function:<REDACTED>,client_context=None,identity=CognitoIdentity([cognito_identity_id=None,cognito_identity_pool_id=None]),tenant_id=None])

To Reproduce

  1. Create a AWS Lambda function to be used as an AWS API Gateway Authorizer
  2. Instrument with Elastic APM using capture_serverless() at entrypoint (handler)
  3. Submit a request to your API Gateway that would invoke the authorizer
  4. Observe error due to context missing value

Environment (please complete the following information)

  • OS: [e.g. Linux] Debian (Docker image: python:3.12-slim)
  • Python version: 3.12
  • Framework and version [e.g. Django 2.1]: N/A
  • APM Server version: 8.18.2
  • Agent version: 6.23.0, Lambda extension: 1.5.8

Additional context

Add any other context about the problem here.

  • Agent config options

    Click to expand
    replace this line with your agent config options
    remember to mask any sensitive fields like tokens
    
  • requirements.txt:

    Click to expand
    replace this line with your `requirements.txt`
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions