diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 2583460c4..550dc16fb 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -738,6 +738,12 @@ class SQSBackend(BaseBackend): if queue.fifo_queue: raise MissingParameter("MessageGroupId") else: + if not queue.fifo_queue: + msg = ( + "Value {} for parameter MessageGroupId is invalid. " + "Reason: The request include parameter that is not valid for this queue type." + ).format(group_id) + raise InvalidParameterValue(msg) message.group_id = group_id if message_attributes: diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 9139969e5..4bb0e0f5d 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -557,6 +557,24 @@ def test_send_message_with_message_group_id(): message_attributes["MessageDeduplicationId"].should.equal("dedupe_id_1") +@mock_sqs +def test_send_message_with_message_group_id_standard_queue(): + sqs = boto3.resource("sqs", region_name="us-east-1") + queue = sqs.create_queue(QueueName=str(uuid4())[0:6]) + + with pytest.raises(ClientError) as ex: + queue.send_message( + MessageBody="mydata", MessageGroupId="group_id_1", + ) + + err = ex.value.response["Error"] + err["Code"].should.equal("InvalidParameterValue") + err["Message"].should.equal( + "Value group_id_1 for parameter MessageGroupId is invalid. " + "Reason: The request include parameter that is not valid for this queue type." + ) + + @mock_sqs def test_send_message_with_unicode_characters(): body_one = "Héllo!😀" @@ -2097,7 +2115,9 @@ def test_delete_message_errors(): @mock_sqs def test_send_message_batch(): client = boto3.client("sqs", region_name="us-east-1") - response = client.create_queue(QueueName=str(uuid4())[0:6]) + response = client.create_queue( + QueueName=f"{str(uuid4())[0:6]}.fifo", Attributes={"FifoQueue": "true"}, + ) queue_url = response["QueueUrl"] response = client.send_message_batch(