Skip to content

fix(parser): accept multi-value headers and query strings in VPC Lattice v2 events - #8774

Closed
Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-vpc-lattice-v2-multivalue-headers
Closed

Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-vpc-lattice-v2-multivalue-headers

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Issue number:
closes #8773

Summary

Changes

  • headers and query_string_parameters in VpcLatticeV2Model are now dict[str, list[str]]. VPC Lattice sends every header and query string value in a V2 event as a list, even a single one (docs). I updated the field descriptions and examples to match.
  • The V2 parser tests used vpcLatticeV2Event.json, which has plain string values that VPC Lattice doesn't send. They now use vpcLatticeV2EventWithHeaders.json, which has the same request context with list values. I didn't change any fixtures, since other tests still use vpcLatticeV2Event.json.
  • Two new tests parse the event captured from a live V2 target group (vpcLatticeV2EventWithQueryString.json), once with the model and once through VpcLatticeV2Envelope.

This is the same fix as aws-powertools/powertools-lambda-typescript#5773.

User experience

Before, every real V2 event failed with a ValidationError, so VpcLatticeV2Model and VpcLatticeV2Envelope couldn't be used with VPC Lattice. Now they parse, and the values come back as lists, like {"header1": ["value1", "value2"]}.

Events with plain string values, like the old test fixture, fail validation now. VPC Lattice never sends that shape, so I treated this as a fix to match the AWS contract (ADR 0006). If you'd rather keep accepting strings with a PowertoolsUserWarning until the next major, I'm happy to change it.

Verification

  • With the model on develop, 6 of the 7 tests in tests/unit/parser/_pydantic/test_vpc_latticev2.py fail: the 4 existing tests that now use list values and the 2 new ones. All 7 pass with this change.
  • tests/unit/parser, tests/unit/data_classes/required_dependencies, tests/functional/parser and tests/functional/event_handler: 1701 passed, 1 skipped (Python 3.12).
  • ruff format --check, ruff check and mypy are clean on the changed files.
  • I didn't set up a VPC Lattice target group. The event shape comes from the VPC Lattice docs and the event captured from a live V2 target group in Bug: VpcLatticeV2Schema rejects every real V2 event powertools-lambda-typescript#5764, which is already in tests/events.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…ice v2 events

VPC Lattice sends every header and query string value in a V2 event as a
list, even when there is only one value. VpcLatticeV2Model typed both
fields as dict[str, str], so every real V2 event failed validation and
VpcLatticeV2Envelope could not parse any of them.

Type both fields as dict[str, list[str]], matching the V2 event structure
in the VPC Lattice docs and the TypeScript parser. The parser tests now
use the list-shaped fixtures, plus the event captured from a live V2
target group.
@Manishram-ai
Manishram-ai requested a review from a team as a code owner November 5, 2026 01:58
@Manishram-ai
Manishram-ai requested a review from hjgraca November 5, 2026 01:58
@boring-cyborg boring-cyborg Bot added the tests label Nov 5, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 5, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@blacksoxx blacksoxx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reads consistent with the service contract to me; I did not run the tests here. One P2 inline on compatibility, which is a maintainer call.

The list shape matches the VPC Lattice docs for the V2 event structure, the captured fixture, the TypeScript fix and the data class, whose query_string_parameters docstring already describes the dict[str, list[str]] shape and joins it with commas. Both fixtures used here carry lists for headers and query strings, so the swapped references in the existing tests hold.

Validation: read the diff at 902d0bc against base f71c5e3; checked the three fixtures and data_classes/vpc_lattice.py on develop. Not run: pytest, mypy. Related: #8777 reports the same bug, #8776 the resolver side of it.

)
headers: dict[str, str] = Field(
description="The request headers as key-value pairs.",
headers: dict[str, list[str]] = Field(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] This turns a ValidationError on for events shaped like the old fixture, which the model accepts on develop. AGENTS.md and ADR 0006 ask for a PowertoolsUserWarning now and the hard failure in the next major when an accepted input turns out to be wrong. One way that keeps the list type: a field_validator("headers", "query_string_parameters", mode="before") that wraps a str value into a one-item list and warns. Whether that is wanted for a shape the service never sends is the maintainers' call; you already offer it in the description, so this is only to make the choice visible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reading through it. I went with the bug fix bullet in ADR 0006, since VPC Lattice never sends plain string values, so the old fixture doesn't match the AWS contract. If the maintainers would rather keep accepting strings with a warning, I'll add the field_validator you described.

@leandrodamascena

Copy link
Copy Markdown
Contributor

Thanks for this, and for the clean diagnosis in #8773. I am closing it, and I want to be upfront about why: this bug makes VpcLatticeV2Model reject every real event, and it is tied to #8776 on the Event Handler side and to how we treat the string shape under ADR 0006. I don't want to split that across two contributors and a few review rounds, so I am taking both fixes myself to get them into 3.40.0, which ships in a few days. Your fixture change and the two tests against the captured event are coming along. You will be credited in the release notes as the reporter and for the first fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants