7

Working on SQS to queue some of my uploads coming from the client. I am getting below error:

com.amazonaws.services.sqs.model.AmazonSQSException: One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes. (Service: AmazonSQS; Status Code: 400; Error Code: InvalidParameterValue; Request ID:

I am using extended client library. Here are the code that I use to send message:

MessageAttributeValue msgAttr = new MessageAttributeValue();
byte [] byteArr=attachment.getBytes();
ByteBuffer buf = ByteBuffer.wrap(byteArr);
msgAttr.setBinaryValue(buf);
msgAttr.setDataType("Binary");
smr.addMessageAttributesEntry("attachment", msgAttr);
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Opv
  • 440
  • 1
  • 3
  • 17

1 Answers1

10

According to the Limits Related to Messages documentation for Amazon SQS:

Message size
The minimum message size is 1 byte (1 character). The maximum is 262,144 bytes (256 KB).

To send messages larger than 256 KB, you can use the Amazon SQS Extended Client Library for Java. This library allows you to send an Amazon SQS message that contains a reference to a message payload in Amazon S3. The maximum payload size is 2 GB.

The library basically stores the data in Amazon S3 and then inserts a reference into the Amazon SQS messages.

For whatever reason, the library enforces a 2GB limit on attachments. You could try and modify the code to handle a larger size file, or you could write your own code that stores the object in Amazon S3 and simply includes a reference to the amazon S3 object within the Amazon SQS messages.

ArslanAnjum
  • 1,674
  • 2
  • 17
  • 31
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Updated to reflect new minimum message size. – John Rotenstein Apr 04 '19 at 08:45
  • 3
    I solved this like, At producer side upload file object in s3 and send s3 path in SQS message and at the consumer, side get S3 key from the message and download the object and delete from s3. pros: No size limit Cons: Both consumer and producer must share access key of S3 – Nitin Mar 06 '20 at 06:03