Skip to content

fix(aws-lambda): build URL query string from Lattice queryStringParameters#4903

Open
rokasta12 wants to merge 1 commit into
honojs:mainfrom
rokasta12:fix/aws-lambda-lattice-query-string
Open

fix(aws-lambda): build URL query string from Lattice queryStringParameters#4903
rokasta12 wants to merge 1 commit into
honojs:mainfrom
rokasta12:fix/aws-lambda-lattice-query-string

Conversation

@rokasta12

Copy link
Copy Markdown
Contributor

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`:

  1. Single value — verifies `c.req.query('q')` returns the Lattice-supplied value.
  2. Repeated values — sends `tag=red&tag=blue`, asserts `c.req.queries('tag')` returns `['red', 'blue']`.
  3. Special characters — sends `John Doe` and asserts the percent-encoded URL round-trips back to the original via `c.req.query('name')`.

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.

  • Add tests
  • Run tests (`bun run test` — 32/32 passes)
  • `bun run format:fix && bun run lint:fix`
  • Add TSDoc/JSDoc — no API surface change

…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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant