fix(aws-lambda): build URL query string from Lattice queryStringParameters#4903
Open
rokasta12 wants to merge 1 commit into
Open
fix(aws-lambda): build URL query string from Lattice queryStringParameters#4903rokasta12 wants to merge 1 commit into
rokasta12 wants to merge 1 commit into
Conversation
…eters `LatticeV2Processor.getQueryString()` returned `''` unconditionally even though `LatticeProxyEventV2.queryStringParameters` is typed as `Record<string, string[] | undefined>` and AWS docs describe it as the canonical query-parameter source for VPC Lattice events. Any Hono route on Lattice that read `c.req.query(...)` saw nothing. Now build the URL query string from the event field, matching how the V1 processor handles `multiValueQueryStringParameters`: encode keys and values, support repeated values per key, drop entries without values. The existing Lattice test embedded a `?...` portion inside `path` to work around the empty-string return. Per the AWS event-shape docs the two fields are disjoint, so the test now uses a plain path and verifies the URL is assembled from `queryStringParameters`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`LatticeV2Processor.getQueryString()` (`src/adapter/aws-lambda/handler.ts:597-599`) returned the empty string unconditionally:
```ts
protected getQueryString(): string {
return ''
}
```
But `LatticeProxyEventV2.queryStringParameters` is typed `Record<string, string[] | undefined>` (handler.ts:34) and the AWS Lattice event-shape docs describe it as the canonical source for query parameters. The result: every Hono route running on a Lattice target saw `c.req.query(...)` and `c.req.queries(...)` return `undefined` / empty even when the client sent query parameters.
Fix
Build the query string from `event.queryStringParameters`, mirroring how V1 handles `multiValueQueryStringParameters` — encode keys and values via `encodeURIComponent`, support repeated values per key, skip entries without values:
```ts
protected getQueryString(event: LatticeProxyEventV2): string {
return Object.entries(event.queryStringParameters || {})
.filter(([, values]) => values && values.length > 0)
.map(([key, values]) =>
values!
.map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&')
)
.join('&')
}
```
Test
Three new behavioral tests in `LatticeV2Processor query string handling`:
All three fail on `main` (return `undefined`/`[]` because `getQueryString` returns `''`); all pass with the fix.
The existing "valid Request object from version 2.0 Lattice event" test embedded the query string inside `path` (`/my/path?...`) as a workaround for the empty-string return. Per the AWS docs `path` and `queryStringParameters` are disjoint fields, so that test is now updated to use a plain path and the URL is assembled from `queryStringParameters` instead — verifying the same end-to-end shape via the canonical field.