Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Moto (5.1.18) Server 500 Error when making a GET request to /.well-known/jwks.json for a mocked Cognito IDP user pool client app #9570

@scottwilkin

Description

@scottwilkin

When running moto server mode to test an API endpoint that does HTTPBearer validation of an access token from Cognito a 500 error is being returned by the werkzeug app.

INFO     werkzeug:_internal.py:97 127.0.0.1 - - [19/Dec/2025 16:33:06] "GET /us-east-1_af38595dbbaa4e61bed9c2f41ec624f0/.well-known/jwks.json HTTP/1.1" 500 -

I'm using the fastapi-cognito library to handle the decoding and validation of access tokens. This library uses httpx to make the async request so I configure the jwks_url config setting to point to the moto server endpoint.

My implementation follows the documentation for setting up a moto server fixture:


@pytest.fixture(scope="module")
def moto_server():
    """Fixture to run a mocked AWS server for testing."""
    # Note: pass `port=0` to get a random free port.
    server = ThreadedMotoServer(port=0)
    server.start()
    host, port = server.get_host_and_port()
    yield f"http://{host}:{port}"
    server.stop()


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions