Skip to content

Bug: VPC Lattice v2 parser model rejects real events because headers and query strings are lists #8773

Open

Description

@Manishram-ai

Expected Behaviour

VpcLatticeV2Model and VpcLatticeV2Envelope parse the events VPC Lattice sends to a Lambda target group that uses the V2 event structure.

Current Behaviour

With the V2 structure, VPC Lattice sends every header and query string value as a list, even when there's only one value. The VPC Lattice docs show "headers": {"header-key": ["header-value", ...]} and "queryStringParameters": {"key": ["value", ...]}, and the multi-value sections on that page say the same.

VpcLatticeV2Model types both fields as dict[str, str], so every real V2 event fails with a ValidationError, and VpcLatticeV2Envelope can't parse any of them.

The repo already has a real V2 event in tests/events/vpcLatticeV2EventWithQueryString.json. It came from a live target group in aws-powertools/powertools-lambda-typescript#5764 and was added in #8572, and it fails to parse. The parser tests pass because they use vpcLatticeV2Event.json, which has plain string values. #8572 listed this as a follow-up, and the TypeScript parser fixed the same schema in aws-powertools/powertools-lambda-typescript#5773.

Code snippet

from aws_lambda_powertools.utilities.parser.models import VpcLatticeV2Model

# Shortened from tests/events/vpcLatticeV2EventWithQueryString.json
event = {
    "version": "2.0",
    "path": "/echo?QS1=value1&QS1=value2&single=one",
    "method": "POST",
    "headers": {
        "content-type": ["application/json"],
        "header1": ["value1", "value2"],
    },
    "queryStringParameters": {"QS1": ["value1", "value2"], "single": ["one"]},
    "body": '{"hello":"world"}',
    "requestContext": {
        "serviceNetworkArn": "arn:aws:vpc-lattice:eu-west-1:123456789012:servicenetwork/sn-0123456789abcdef0",
        "serviceArn": "arn:aws:vpc-lattice:eu-west-1:123456789012:service/svc-0123456789abcdef0",
        "targetGroupArn": "arn:aws:vpc-lattice:eu-west-1:123456789012:targetgroup/tg-0123456789abcdef0",
        "identity": {"sourceVpcArn": "arn:aws:ec2:eu-west-1:123456789012:vpc/vpc-0123456789abcdef0"},
        "region": "eu-west-1",
        "timeEpoch": "1790935900260914",
    },
}

VpcLatticeV2Model(**event)
pydantic_core._pydantic_core.ValidationError: 4 validation errors for VpcLatticeV2Model
headers.content-type
  Input should be a valid string [type=string_type, input_value=['application/json'], input_type=list]
headers.header1
  Input should be a valid string [type=string_type, input_value=['value1', 'value2'], input_type=list]
queryStringParameters.QS1
  Input should be a valid string [type=string_type, input_value=['value1', 'value2'], input_type=list]
queryStringParameters.single
  Input should be a valid string [type=string_type, input_value=['one'], input_type=list]

Possible Solution

Type headers and queryStringParameters as dict[str, list[str]], like multiValueHeaders in the API Gateway model.

Steps to Reproduce

Run the snippet above. Parsing tests/events/vpcLatticeV2EventWithQueryString.json with VpcLatticeV2Model, or with parse(..., envelope=envelopes.VpcLatticeV2Envelope), fails the same way.

Powertools for AWS Lambda (Python) version

latest

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