Skip to content

Bug: Bedrock Agent kwargs and null content type, AppSync decorator returns None and context leak, Router duplicates, Function URL base path, Depends() with a class #8584

Open

Description

@leandrodamascena

Expected Behaviour

  • Bedrock Agent: only path parameters are injected as kwargs when validation is off, and a Response without content type produces a valid media type key.
  • AppSync Events: a decorator with an invalid path still returns the function. AppSync: app.context is cleared after every invocation, including when an exception handler runs.
  • Router warns on duplicate routes like the resolver does; LambdaFunctionUrlResolver._get_base_path checks the path; Depends(SomeClass) honours the __init__ signature.

Current Behaviour

  1. BedrockAgentResolver(enable_validation=False) passes every event parameter as a kwarg (bedrock_agent.py:350). A query parameter not in the handler signature raises TypeError: unexpected keyword argument. With validation on the middleware rewrites _route_args and masks it.
  2. A Response without content type produces "responseBody": {"null": {...}} (bedrock_agent.py:52).
  3. @app.on_publish("/default/*/sub") warns "will be skipped" and returns None, so the decorated function disappears (events_appsync/_registry.py:56).
  4. AppSyncResolver.resolve() returns the exception handler result before clear_context(), so app.context leaks into the next invocation (appsync.py:160). The docs say context is cleared after each invocation.
  5. Router silently overwrites a duplicate route, last wins (api_gateway.py:3185). The resolver warns and keeps the first.
  6. LambdaFunctionUrlResolver._get_base_path compares request_context.http.method instead of .path (lambda_function_url.py:57). Unreachable today since Function URLs only use $default, but it is a typo.
  7. Depends(SomeClass) uses get_type_hints(cls), which returns class-level annotations, not __init__ parameters (depends.py:121, 201). A class dependency cannot receive Request or a nested Depends: DependencyResolutionError: Svc.__init__() missing 1 required positional argument.

Code snippet

import warnings
from typing import Annotated
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, AppSyncEventsResolver, AppSyncResolver, BedrockAgentResolver, Depends, Request, Response
from aws_lambda_powertools.event_handler.api_gateway import Router
from tests.functional.utils import load_event

ev = load_event("bedrockAgentEventWithPathParams.json")
ev["parameters"].append({"type": "string", "name": "verbose", "value": "true"})
b = BedrockAgentResolver(enable_validation=False)
@b.get("/claims/<claim_id>", description="d")
def g(claim_id: str): return {"claim_id": claim_id}
b.resolve(ev, None)  # TypeError: g() got an unexpected keyword argument 'verbose'

events = AppSyncEventsResolver()
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    @events.on_publish("/default/*/sub")
    def h4(payload): return payload
print(h4)  # None

gql = AppSyncResolver()
@gql.exception_handler(ValueError)
def eh(e): return {"error": str(e)}
@gql.resolver(type_name="Mutation", field_name="createSomething")
def c(**kw): gql.append_context(x=1); raise ValueError("bad")
gql.resolve(load_event("appSyncDirectResolver.json"), None); print(gql.context)  # {'x': 1}

router = Router()
@router.get("/my/path")
def a(): return {"fn": "a"}
@router.get("/my/path")
def bb(): return {"fn": "b"}
app = APIGatewayRestResolver(); app.include_router(router)  # no warning
print(app.resolve(load_event("apiGatewayProxyEvent.json"), None)["body"])  # {"fn":"b"}

class Svc:
    def __init__(self, request: Request): self.path = request.resolved_event.path
app2 = APIGatewayRestResolver()
@app2.get("/my/path")
def h(svc: Annotated[Svc, Depends(Svc)]): return {"path": svc.path}
app2.resolve(load_event("apiGatewayProxyEvent.json"), None)  # DependencyResolutionError

Possible Solution

Filter Bedrock kwargs to match.groupdict() keys and default the content type to application/json; return func in the AppSync Events registry; wrap AppSync clear_context() in try/finally; warn in Router.route on duplicate keys; use .http.path in Function URL; inspect fn.__init__ when the dependency is a class.

Steps to Reproduce

Run the snippet above with the tests/events fixtures. Full context in #8576.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

Warning

This issue is ready to be picked up, by humans or by agents. If you want it, comment here first so we can assign it to you, and please take only one or two issues at a time so others can join in too. Thanks!

Activity

  1. added this to the 3.39.0 milestone on Oct 18, 2026
  2. vishwakt commented on Oct 19, 2026

    @vishwakt
    Contributor

    I'll take this one. I verified all seven against today's develop before claiming and they reproduce as described. Planning a single PR with one fix plus test per bug, happy to split it up if you'd rather review them separately.

  3. leandrodamascena commented on Oct 19, 2026

    @leandrodamascena
    ContributorAuthor

    Hey @vishwakt pls go ahead, thanks for checking all seven against develop first. Will review #8629.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions