aws-samples / aws-samples/sample-bedrock-proxy-gateway
Streaming error responses send JSON into an eventstream body -> clients fail with ChecksumMismatch
- Dominant language
- Python
- Stars
- 12
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Context
On the streaming endpoints, mid-stream errors are emitted as raw JSON into a response whose Content-Type is `application/vnd.amazon.eventstream`. AWS SDK clients (e.g. boto3) parse that body strictly as binary EventStream frames, so the JSON is misread as a frame header and the client fails with `ChecksumMismatch`.
Once a stream has started the HTTP status is committed, so a mid-stream error must be sent as an EventStream frame, not JSON.
## Affected code
1) `aws_error_response.py`- `create_aws_error_json()` returns plain JSON bytes.
2) `bedrock_routes.py`- that JSON is yielded into the `converse-stream` and `invoke-with-response-stream` SSE generators (the `except httpx.HTTPStatusError` / `except Exception` branches).
## Suggested fix
1) Add an EventStream frame builder in `aws_error_response.py` and use it in the streaming error paths instead of `create_aws_error_json`.
2) In `bedrock_routes.py`, in both streaming generators, replace each yield `create_aws_error_json(...)` with `yield create_aws_error_event(...)`
Note: Reproducible by feeding `create_aws_error_json(...)` output into `botocore.eventstream.EventStreamBuffer` → `ChecksumMismatch`.
Contributor guide
Research direction
Start with aws_error_response.py and bedrock_routes.py, focusing on create_aws_error_json and the exception branches in both streaming generators. Use botocore.eventstream.EventStreamBuffer with the generated response to reproduce the failure. Done means mid-stream errors are emitted as valid EventStream frames and the affected AWS SDK clients no longer fail with ChecksumMismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100