67
67
from localstack .services .edge import ROUTER
68
68
from localstack .services .plugins import ServiceLifecycleHook
69
69
from localstack .services .sqs import constants as sqs_constants
70
- from localstack .services .sqs .exceptions import InvalidParameterValue
70
+ from localstack .services .sqs .exceptions import InvalidParameterValueException
71
71
from localstack .services .sqs .models import (
72
72
FifoQueue ,
73
73
SqsMessage ,
@@ -109,15 +109,15 @@ def assert_queue_name(queue_name: str, fifo: bool = False):
109
109
if queue_name .endswith (".fifo" ):
110
110
if not fifo :
111
111
# Standard queues with .fifo suffix are not allowed
112
- raise InvalidParameterValue (
112
+ raise InvalidParameterValueException (
113
113
"Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"
114
114
)
115
115
# The .fifo suffix counts towards the 80-character queue name quota.
116
116
queue_name = queue_name [:- 5 ] + "_fifo"
117
117
118
118
# slashes are actually not allowed, but we've allowed it explicitly in localstack
119
119
if not re .match (r"^[a-zA-Z0-9/_-]{1,80}$" , queue_name ):
120
- raise InvalidParameterValue (
120
+ raise InvalidParameterValueException (
121
121
"Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"
122
122
)
123
123
@@ -133,7 +133,7 @@ def check_message_size(
133
133
_message_body_size (message_body ) + _message_attributes_size (message_attributes )
134
134
> max_message_size
135
135
):
136
- raise InvalidParameterValue (error )
136
+ raise InvalidParameterValueException (error )
137
137
138
138
139
139
def _message_body_size (body : str ):
@@ -386,31 +386,31 @@ def check_attributes(message_attributes: MessageBodyAttributeMap):
386
386
return
387
387
for attribute_name in message_attributes :
388
388
if len (attribute_name ) >= 256 :
389
- raise InvalidParameterValue (
389
+ raise InvalidParameterValueException (
390
390
"Message (user) attribute names must be shorter than 256 Bytes"
391
391
)
392
392
if not re .match (sqs_constants .ATTR_NAME_CHAR_REGEX , attribute_name .lower ()):
393
- raise InvalidParameterValue (
393
+ raise InvalidParameterValueException (
394
394
"Message (user) attributes name can only contain upper and lower score characters, digits, periods, "
395
395
"hyphens and underscores. "
396
396
)
397
397
if not re .match (sqs_constants .ATTR_NAME_PREFIX_SUFFIX_REGEX , attribute_name .lower ()):
398
- raise InvalidParameterValue (
398
+ raise InvalidParameterValueException (
399
399
"You can't use message attribute names beginning with 'AWS.' or 'Amazon.'. "
400
400
"These strings are reserved for internal use. Additionally, they cannot start or end with '.'."
401
401
)
402
402
403
403
attribute = message_attributes [attribute_name ]
404
404
attribute_type = attribute .get ("DataType" )
405
405
if not attribute_type :
406
- raise InvalidParameterValue ("Missing required parameter DataType" )
406
+ raise InvalidParameterValueException ("Missing required parameter DataType" )
407
407
if not re .match (sqs_constants .ATTR_TYPE_REGEX , attribute_type ):
408
- raise InvalidParameterValue (
408
+ raise InvalidParameterValueException (
409
409
f"Type for parameter MessageAttributes.Attribute_name.DataType must be prefixed"
410
410
f'with "String", "Binary", or "Number", but was: { attribute_type } '
411
411
)
412
412
if len (attribute_type ) >= 256 :
413
- raise InvalidParameterValue (
413
+ raise InvalidParameterValueException (
414
414
"Message (user) attribute types must be shorter than 256 Bytes"
415
415
)
416
416
@@ -419,25 +419,25 @@ def check_attributes(message_attributes: MessageBodyAttributeMap):
419
419
attribute_value = attribute .get ("StringValue" )
420
420
421
421
if not attribute_value :
422
- raise InvalidParameterValue (
422
+ raise InvalidParameterValueException (
423
423
f"Message (user) attribute '{ attribute_name } ' must contain a non-empty value of type 'String'."
424
424
)
425
425
426
426
check_message_content (attribute_value )
427
427
except InvalidMessageContents as e :
428
428
# AWS throws a different exception here
429
- raise InvalidParameterValue (e .args [0 ])
429
+ raise InvalidParameterValueException (e .args [0 ])
430
430
431
431
432
432
def check_fifo_id (fifo_id ):
433
433
if not fifo_id :
434
434
return
435
435
if len (fifo_id ) >= 128 :
436
- raise InvalidParameterValue (
436
+ raise InvalidParameterValueException (
437
437
"Message deduplication ID and group ID must be shorter than 128 bytes"
438
438
)
439
439
if not re .match (sqs_constants .FIFO_MSG_REGEX , fifo_id ):
440
- raise InvalidParameterValue (
440
+ raise InvalidParameterValueException (
441
441
"Invalid characters found. Deduplication ID and group ID can only contain"
442
442
"alphanumeric characters as well as TODO"
443
443
)
@@ -618,25 +618,37 @@ def on_before_stop(self):
618
618
self ._stop_cloudwatch_metrics_reporting ()
619
619
620
620
@staticmethod
621
- def _require_queue (account_id : str , region_name : str , name : str ) -> SqsQueue :
621
+ def _require_queue (
622
+ account_id : str , region_name : str , name : str , is_query : bool = False
623
+ ) -> SqsQueue :
622
624
"""
623
625
Returns the queue for the given name, or raises QueueDoesNotExist if it does not exist.
624
626
625
627
:param: context: the request context
626
628
:param name: the name to look for
629
+ :param is_query: whether the request is using query protocol (error message is different)
627
630
:returns: the queue
628
631
:raises QueueDoesNotExist: if the queue does not exist
629
632
"""
630
633
store = SqsProvider .get_store (account_id , region_name )
631
634
with _STORE_LOCK :
632
635
if name not in store .queues .keys ():
633
- raise QueueDoesNotExist ("The specified queue does not exist for this wsdl version." )
636
+ if is_query :
637
+ message = "The specified queue does not exist for this wsdl version."
638
+ else :
639
+ message = "The specified queue does not exist."
640
+ raise QueueDoesNotExist (message )
634
641
635
642
return store .queues [name ]
636
643
637
644
def _require_queue_by_arn (self , context : RequestContext , queue_arn : str ) -> SqsQueue :
638
645
arn = parse_arn (queue_arn )
639
- return self ._require_queue (arn ["account" ], arn ["region" ], arn ["resource" ])
646
+ return self ._require_queue (
647
+ arn ["account" ],
648
+ arn ["region" ],
649
+ arn ["resource" ],
650
+ is_query = context .service .service_name == "sqs-query" ,
651
+ )
640
652
641
653
def _resolve_queue (
642
654
self ,
@@ -655,7 +667,10 @@ def _resolve_queue(
655
667
:raises QueueDoesNotExist: if the queue does not exist
656
668
"""
657
669
account_id , region_name , name = resolve_queue_location (context , queue_name , queue_url )
658
- return self ._require_queue (account_id , region_name or context .region , name )
670
+ is_query = context .service .service_name == "sqs-query"
671
+ return self ._require_queue (
672
+ account_id , region_name or context .region , name , is_query = is_query
673
+ )
659
674
660
675
def create_queue (
661
676
self ,
@@ -722,11 +737,12 @@ def create_queue(
722
737
def get_queue_url (
723
738
self , context : RequestContext , queue_name : String , queue_owner_aws_account_id : String = None
724
739
) -> GetQueueUrlResult :
725
- store = self .get_store (queue_owner_aws_account_id or context .account_id , context .region )
726
- if queue_name not in store .queues .keys ():
727
- raise QueueDoesNotExist ("The specified queue does not exist for this wsdl version." )
728
-
729
- queue = store .queues [queue_name ]
740
+ queue = self ._require_queue (
741
+ queue_owner_aws_account_id or context .account_id ,
742
+ context .region ,
743
+ queue_name ,
744
+ is_query = context .service .service_name == "sqs-query" ,
745
+ )
730
746
731
747
return GetQueueUrlResult (QueueUrl = queue .url (context ))
732
748
@@ -1011,7 +1027,7 @@ def receive_message(
1011
1027
elif (
1012
1028
num < 1 or num > MAX_NUMBER_OF_MESSAGES
1013
1029
) and not SQS_DISABLE_MAX_NUMBER_OF_MESSAGE_LIMIT :
1014
- raise InvalidParameterValue (
1030
+ raise InvalidParameterValueException (
1015
1031
f"Value { num } for parameter MaxNumberOfMessages is invalid. "
1016
1032
f"Reason: Must be between 1 and 10, if provided."
1017
1033
)
@@ -1153,18 +1169,20 @@ def set_queue_attributes(
1153
1169
max_receive_count = _redrive_policy .get ("maxReceiveCount" )
1154
1170
# TODO: use the actual AWS responses
1155
1171
if not dl_target_arn :
1156
- raise InvalidParameterValue (
1172
+ raise InvalidParameterValueException (
1157
1173
"The required parameter 'deadLetterTargetArn' is missing"
1158
1174
)
1159
1175
if max_receive_count is None :
1160
- raise InvalidParameterValue ("The required parameter 'maxReceiveCount' is missing" )
1176
+ raise InvalidParameterValueException (
1177
+ "The required parameter 'maxReceiveCount' is missing"
1178
+ )
1161
1179
try :
1162
1180
max_receive_count = int (max_receive_count )
1163
1181
valid_count = 1 <= max_receive_count <= 1000
1164
1182
except ValueError :
1165
1183
valid_count = False
1166
1184
if not valid_count :
1167
- raise InvalidParameterValue (
1185
+ raise InvalidParameterValueException (
1168
1186
f"Value { redrive_policy } for parameter RedrivePolicy is invalid. Reason: Invalid value for "
1169
1187
f"maxReceiveCount: { max_receive_count } , valid values are from 1 to 1000 both inclusive."
1170
1188
)
@@ -1233,7 +1251,7 @@ def _validate_actions(self, actions: ActionNameList):
1233
1251
1234
1252
for action in actions :
1235
1253
if action not in valid :
1236
- raise InvalidParameterValue (
1254
+ raise InvalidParameterValueException (
1237
1255
f"Value SQS:{ action } for parameter ActionName is invalid. Reason: Please refer to the appropriate "
1238
1256
"WSDL for a list of valid actions. "
1239
1257
)
@@ -1260,12 +1278,12 @@ def _assert_batch(
1260
1278
"It can be at most 80 letters long."
1261
1279
)
1262
1280
if require_message_deduplication_id and not entry .get ("MessageDeduplicationId" ):
1263
- raise InvalidParameterValue (
1281
+ raise InvalidParameterValueException (
1264
1282
"The queue should either have ContentBasedDeduplication enabled or "
1265
1283
"MessageDeduplicationId provided explicitly"
1266
1284
)
1267
1285
if require_fifo_queue_params and not entry .get ("MessageGroupId" ):
1268
- raise InvalidParameterValue (
1286
+ raise InvalidParameterValueException (
1269
1287
"The request must contain the parameter MessageGroupId."
1270
1288
)
1271
1289
if entry_id in visited :
0 commit comments