Skip to content

Bug: AlbModel rejects events when the target group has multi-value headers enabled #8847

Open

Description

@Manishram-ai

Expected Behaviour

When a Lambda target group has multi-value headers turned on, ALB sends multiValueHeaders and multiValueQueryStringParameters instead of headers and queryStringParameters (ALB docs). AlbModel should parse those events and keep the multi-value fields.

Current Behaviour

AlbModel requires headers and queryStringParameters and doesn't have the multi-value fields, so every event from a target group with that setting fails with a ValidationError. The two multi-value ALB events in the repo, tests/events/albMultiValueHeadersEvent.json and tests/events/albMultiValueQueryStringEvent.json, both fail to parse.

The ALBEvent data class and ALBResolver already work with both shapes, and the TypeScript AlbSchema accepts both too.

Code snippet

import json

from aws_lambda_powertools.utilities.parser import parse
from aws_lambda_powertools.utilities.parser.models import AlbModel

with open("tests/events/albMultiValueQueryStringEvent.json") as f:
    event = json.load(f)

parsed = parse(event=event, model=AlbModel)
print(parsed.multiValueQueryStringParameters)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for AlbModel
headers
  Field required [type=missing, input_value={'requestContext': {'elb'...isBase64Encoded': False}, input_type=dict]
queryStringParameters
  Field required [type=missing, input_value={'requestContext': {'elb'...isBase64Encoded': False}, input_type=dict]

Possible Solution

Add multiValueHeaders and multiValueQueryStringParameters to AlbModel, and give all four header and query string fields an empty dict as the default. That's what ALBEvent returns for the fields ALB leaves out, and headers keeps its dict[str, str] type, so existing handlers don't need a None check. With that change the snippet prints {'parameter1': ['value1', 'value2'], 'parameter2': ['value']}.

Steps to Reproduce

Run the snippet above from the repo root. albMultiValueHeadersEvent.json fails the same way.

Did you run the reproduction yourself?

Powertools for AWS Lambda (Python) version

3.40.0

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions