aws-samples / aws-samples/bedrock-chat
Exceeding SQS message size limit when attaching image via a customized bot published API
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 535
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 10
Description
## Describe the bug
When I call an API published with an image encoded to base64, the API returns 500 error with following detail:
```
'detail': 'An error occurred (InvalidParameterValue) when '
'calling the SendMessage operation: One or more '
'parameters are invalid. Reason: Message must be '
'shorter than 262144 bytes.'
```
This is due to a hard limit of SQS message size ([document](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html))
## To Reproduce
1. publish customized API
2. run following code
```python
import base64
import json
import requests
from pprint import pprint
base_url = ""
headers = {
"Content-Type": "application/json",
"x-api-key": ""
}
input_data = "describe what is in the image"
image_path = "" #image size to be >~200KB
def start_conversation(model, message, image_files):
url = f"{base_url}/conversation"
content = [
{
"contentType": "text",
"body": message
}
]
for image_file in image_files:
with open(image_file, "rb") as f:
image_data = f.read()
image_base64 = base64.b64encode(image_data).decode('utf-8')
content.append({
"contentType": "image",
"mediaType": "image/png", #or other appropriate MIME type
"body": image_base64
})
payload = {
"message": {
"content": content,
"model": model
}
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
if response.status_code == 200:
data = response.json()
return data
else:
return {"status": f"Failed to start conversation with status code {response.status_code}", "response":response.json()}
conversation_start_result = start_conversation("claude-v3-sonnet", input_data, [image_path])
pprint(conversation_start_result)
```
## Screenshots
N/A
## Additional context
N/A
Contributor guide
Research direction
Start by reproducing the published API request at the conversation endpoint with an image larger than approximately 200 KB, and trace where the request reaches Amazon SQS. Confirm the 262144-byte message limit and identify the API path responsible; done means image requests no longer fail with the reported SQS size error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100