diff --git a/moto/sqs/exceptions.py b/moto/sqs/exceptions.py index d72cfdffc..c9d0d73c5 100644 --- a/moto/sqs/exceptions.py +++ b/moto/sqs/exceptions.py @@ -11,6 +11,11 @@ class ReceiptHandleIsInvalid(Exception): status_code = 400 +class InvalidParameterValue(Exception): + description = "One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes." + status_code = 400 + + class MessageAttributesInvalid(Exception): status_code = 400 diff --git a/moto/sqs/models.py b/moto/sqs/models.py index efb75dd9c..725465498 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -12,7 +12,8 @@ from moto.core.utils import camelcase_to_underscores, get_random_message_id from .utils import generate_receipt_handle, unix_time_millis from .exceptions import ( ReceiptHandleIsInvalid, - MessageNotInflight + MessageNotInflight, + InvalidParameterValue, ) DEFAULT_ACCOUNT_ID = 123456789012 @@ -251,6 +252,9 @@ class SQSBackend(BaseBackend): else: delay_seconds = queue.delay_seconds + if len(message_body) > self.maximum_message_size: + raise InvalidParameterValue + message_id = get_random_message_id() message = Message(message_id, message_body)