Repository: getmoto/moto (python)

Issue:
SQS: get_queue_by_name does not raise QueueDoesNotExist exception when queue does not exist
With botocore 1.34.17, attempting to load or get a non-existent SQS queue would raise a sqs.meta.client.exceptions.QueueDoesNotExist exception.  With newer versions of the boto package, this exception is no longer raised when using moto and the more general ClientError exception is raised instead.

Versions:
- moto v5.0.10
- boto3 v1.34.138
- botocore v1.34.138
- Python v3.12.3

Working versions:
 - boto3 v1.34.17
 - botocore v.1.34.17

I am using moto mocks

It appears that newer versions of boto do not contain fully qualified names like "AWS.SimpleQueueService.NonExistentQueue" in it's exception map.  In newer versions of boto, the QueryErrorCode property is set to "QueueDoesNotExist" when calling real AWS while the ErrorCode is still "AWS.SimpleQueueService.NonExistentQueue".  The QueryErrorCode takes precedence over ErrorCode when mapping exceptions per this code in botocore.client, and moto is not setting QueryErrorCode, only ErrorCode
```
       # botocore.client line 1015
        if http.status_code >= 300:
            error_info = parsed_response.get("Error", {})
            error_code = error_info.get("QueryErrorCode") or error_info.get(
                "Code"
            )
            error_class = self.exceptions.from_code(error_code)
            raise error_class(parsed_response, operation_name)
        else:
            return parsed_response
```

## Steps to reproduce
```
from moto import mock_aws
import pytest

@mock_aws
def test_queue_not_exists_exception():
    from boto3 import resource

    sqs = resource("sqs")
    with pytest.raises(sqs.meta.client.exceptions.QueueDoesNotExist):
        sqs.get_queue_by_name(QueueName="doesnotexist")
```




Pull request:
SQS: Improve error handling for unknown queues
All relevant tests are now verified against AWS.

Fixes #7827 

Patch:
diff --git a/docs/docs/configuration/index.rst b/docs/docs/configuration/index.rst
index 9466d7497..ba0b50358 100644
--- a/docs/docs/configuration/index.rst
+++ b/docs/docs/configuration/index.rst
@@ -20,6 +20,7 @@ If you are using the decorators, some options are configurable within the decora
                 "services": ["dynamodb"]
             },
             "reset_boto3_session": True,
+            "service_whitelist": None,
         },
         "iam": {"load_aws_managed_policies": False},
         "stepfunctions": {"execute_state_machine": True},
@@ -52,6 +53,17 @@ That is why Moto resets the `boto3-Session`, to make sure that it is recreated w
 
 If all of your tests use Moto, and you never want to reach out to AWS, you can choose to _not_ reset the `boto3-session`. New boto3-clients that are created will reuse the `boto3-Session` (with fake credentials), making Moto much more performant.
 
+Whitelist Services
+-------------------
+The `mock_aws` decorator will allow requests to all supported services. If you want to restrict this to only specific services, you can configure a service whitelist.
+For example, if you only want your application to use DynamoDB and S3:
+
+```
+mock_aws(config={"core": {"service_whitelist": ["dynamodb", "s3"]}})
+```
+
+If the application under test tries to access any other services, Moto will throw a `ServiceNotWhitelisted`-exception.
+
 AWS Managed Policies
 --------------------
 Moto comes bundled with all Managed Policies that AWS exposes, which are updated regularly. However, they are not loaded unless specifically requested for performance reasons.
diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py
index ce66fef66..7943659cc 100644
--- a/moto/awslambda/models.py
+++ b/moto/awslambda/models.py
@@ -1150,9 +1150,9 @@ class LambdaFunction(CloudFormationModel, DockerModel):
         spec = {
             "Code": properties["Code"],
             "FunctionName": resource_name,
-            "Handler": properties["Handler"],
+            "Handler": properties.get("Handler"),
             "Role": properties["Role"],
-            "Runtime": properties["Runtime"],
+            "Runtime": properties.get("Runtime"),
         }
 
         # NOTE: Not doing `properties.get(k, DEFAULT)` to avoid duplicating the
diff --git a/moto/core/botocore_stubber.py b/moto/core/botocore_stubber.py
index 929326168..0872fc8f3 100644
--- a/moto/core/botocore_stubber.py
+++ b/moto/core/botocore_stubber.py
@@ -7,7 +7,8 @@ from botocore.awsrequest import AWSResponse
 import moto.backend_index as backend_index
 from moto.core.base_backend import BackendDict
 from moto.core.common_types import TYPE_RESPONSE
-from moto.core.config import passthrough_service, passthrough_url
+from moto.core.config import passthrough_service, passthrough_url, service_whitelisted
+from moto.core.exceptions import ServiceNotWhitelisted
 from moto.core.utils import get_equivalent_url_in_aws_domain
 
 
@@ -56,6 +57,9 @@ class BotocoreStubber:
                 if passthrough_service(service):
                     return None
 
+                if not service_whitelisted(service):
+                    raise ServiceNotWhitelisted(service)
+
                 import moto.backends as backends
                 from moto.core import DEFAULT_ACCOUNT_ID
                 from moto.core.exceptions import HTTPException
diff --git a/moto/core/config.py b/moto/core/config.py
index 1b6cfa72b..47a3e27ee 100644
--- a/moto/core/config.py
+++ b/moto/core/config.py
@@ -1,5 +1,5 @@
 import re
-from typing import List, TypedDict
+from typing import List, Optional, TypedDict
 
 
 class _docker_config(TypedDict, total=False):
@@ -15,6 +15,7 @@ class _core_config(TypedDict, total=False):
     mock_credentials: bool
     passthrough: _passthrough_config
     reset_boto3_session: bool
+    service_whitelist: Optional[List[str]]
 
 
 class _iam_config(TypedDict, total=False):
@@ -49,6 +50,7 @@ default_user_config: DefaultConfig = {
         "mock_credentials": True,
         "passthrough": {"urls": [], "services": []},
         "reset_boto3_session": True,
+        "service_whitelist": None,
     },
     "iam": {"load_aws_managed_policies": False},
     "stepfunctions": {"execute_state_machine": False},
@@ -56,6 +58,11 @@ default_user_config: DefaultConfig = {
 }
 
 
+def service_whitelisted(service: str) -> bool:
+    services_whitelisted = default_user_config.get("core", {}).get("service_whitelist")
+    return services_whitelisted is None or service in services_whitelisted
+
+
 def passthrough_service(service: str) -> bool:
     passthrough_services = (
         default_user_config.get("core", {}).get("passthrough", {}).get("services", [])
diff --git a/moto/core/exceptions.py b/moto/core/exceptions.py
index 69a5ae457..86595bc8e 100644
--- a/moto/core/exceptions.py
+++ b/moto/core/exceptions.py
@@ -200,3 +200,15 @@ class InvalidToken(AWSError):
 
     def __init__(self, message: str = "Invalid token"):
         super().__init__(f"Invalid Token: {message}", "InvalidToken")
+
+
+class ServiceNotWhitelisted(Exception):
+    def __init__(self, service_name: str):
+        from moto.settings import default_user_config
+
+        services_whitelisted = default_user_config.get("core", {}).get(
+            "service_whitelist"
+        )
+        super().__init__(
+            f"Service {service_name} not whitelisted. Only services {services_whitelisted} are allowed."
+        )
diff --git a/moto/sqs/exceptions.py b/moto/sqs/exceptions.py
index d2f483c4e..7207d4488 100644
--- a/moto/sqs/exceptions.py
+++ b/moto/sqs/exceptions.py
@@ -18,7 +18,7 @@ class MessageAttributesInvalid(RESTError):
 
 
 class QueueDoesNotExist(RESTError):
-    code = 400
+    code = 404
 
     def __init__(self) -> None:
         super().__init__(
diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py
index 3c84d2710..8a9e077f5 100644
--- a/moto/sqs/responses.py
+++ b/moto/sqs/responses.py
@@ -136,10 +136,18 @@ class SQSResponse(BaseResponse):
     def call_action(self) -> TYPE_RESPONSE:
         status_code, headers, body = super().call_action()
         if status_code == 404:
-            queue_name = self.querystring.get("QueueName", [""])[0]
-            template = self.response_template(ERROR_INEXISTENT_QUEUE)
-            response = template.render(queue_name=queue_name)
-            return 404, headers, response
+            if self.is_json():
+                err = {
+                    "__type": "com.amazonaws.sqs#QueueDoesNotExist",
+                    "message": "The specified queue does not exist.",
+                }
+                headers["x-amzn-query-error"] = (
+                    "AWS.SimpleQueueService.NonExistentQueue;Sender"
+                )
+                body = json.dumps(err)
+            else:
+                body = self.response_template(ERROR_INEXISTENT_QUEUE).render()
+            status_code = 400
         return status_code, headers, body
 
     def _error(self, code: str, message: str, status: int = 400) -> TYPE_RESPONSE:


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 000000000..f723cf5f3
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,18 @@
+import boto3
+import pytest
+
+from moto import mock_aws
+
+
+@pytest.fixture(scope="function")
+def account_id():
+    """Return the current Account ID. Will reach out to AWS if so configured."""
+    from . import allow_aws_request
+
+    if allow_aws_request():
+        identity = boto3.client("sts", "us-east-1").get_caller_identity()
+        yield identity["Account"]
+    else:
+        with mock_aws():
+            identity = boto3.client("sts", "us-east-1").get_caller_identity()
+            yield identity["Account"]
diff --git a/tests/test_awslambda/test_awslambda_cloudformation.py b/tests/test_awslambda/test_awslambda_cloudformation.py
index 09e3edf8c..6e1198a0f 100644
--- a/tests/test_awslambda/test_awslambda_cloudformation.py
+++ b/tests/test_awslambda/test_awslambda_cloudformation.py
@@ -1,4 +1,5 @@
 import io
+import json
 import re
 import zipfile
 from string import Template
@@ -54,6 +55,26 @@ template = Template(
 }"""
 )
 
+
+code_image_template = {
+    "AWSTemplateFormatVersion": "2010-09-09",
+    "Resources": {
+        "LambdaFunction": {
+            "Type": "AWS::Lambda::Function",
+            "Properties": {
+                "FunctionName": "ContainerLambdaFunction",
+                "Role": "dummy-role-arn",
+                "Code": {
+                    "ImageUri": "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-lambda-container:latest"
+                },
+                "PackageType": "Image",
+                "MemorySize": 128,
+                "Timeout": 30,
+            },
+        }
+    },
+}
+
 event_source_mapping_template = Template(
     """{
     "AWSTemplateFormatVersion": "2010-09-09",
@@ -114,6 +135,25 @@ def test_lambda_can_be_deleted_by_cloudformation():
     assert e.value.response["Error"]["Code"] == "ResourceNotFoundException"
 
 
+@mock_aws
+def test_lambda_with_code_image_can_be_created():
+    our_template = code_image_template.copy()
+    our_template["Resources"]["LambdaFunction"]["Properties"]["Role"] = get_role_arn()
+    stack_name = f"stack{str(uuid4())[0:6]}"
+    cf = boto3.client("cloudformation", region_name="us-east-1")
+    cf.create_stack(StackName=stack_name, TemplateBody=json.dumps(code_image_template))
+
+    lmbda = boto3.client("lambda", region_name="us-east-1")
+    functions = lmbda.list_functions()["Functions"]
+    function_names = [f["FunctionName"] for f in functions]
+    assert "ContainerLambdaFunction" in function_names
+
+    cf.delete_stack(StackName=stack_name)
+    functions = lmbda.list_functions()["Functions"]
+    function_names = [f["FunctionName"] for f in functions]
+    assert "ContainerLambdaFunction" not in function_names
+
+
 @mock_aws
 def test_event_source_mapping_create_from_cloudformation_json():
     sqs = boto3.resource("sqs", region_name="us-east-1")
diff --git a/tests/test_core/test_config.py b/tests/test_core/test_config.py
index 63ba387ff..20b2d5939 100644
--- a/tests/test_core/test_config.py
+++ b/tests/test_core/test_config.py
@@ -1,3 +1,7 @@
+from unittest import SkipTest
+
+import boto3
+import pytest
 import requests
 
 from moto import mock_aws, settings
@@ -6,6 +10,7 @@ from moto.awslambda.utils import get_backend
 from moto.awslambda_simple.models import LambdaSimpleBackend
 from moto.core import DEFAULT_ACCOUNT_ID
 from moto.core.config import default_user_config
+from moto.core.exceptions import ServiceNotWhitelisted
 
 
 @mock_aws
@@ -50,3 +55,33 @@ def test_change_configuration_using_api() -> None:
         f"http://{base_url}/moto-api/config",
         json={"batch": {"use_docker": True}, "lambda": {"use_docker": True}},
     )
+
+
+def test_whitelist() -> None:
+    if not settings.TEST_DECORATOR_MODE:
+        raise SkipTest("No point in testing this anywhere else")
+
+    with mock_aws(config={"core": {"service_whitelist": ["s3"]}}):
+        dynamodb = boto3.client("dynamodb", "us-east-1")
+        s3 = boto3.client("s3", "us-east-1")
+
+        # S3 is whitelisted, so all calls are allowed
+        s3.list_buckets()
+
+        # DynamoDB is not whitelisted
+        with pytest.raises(ServiceNotWhitelisted):
+            dynamodb.list_tables()
+
+    # Empty whitelist, so no calls are allowed
+    with mock_aws(config={"core": {"service_whitelist": []}}):
+        with pytest.raises(ServiceNotWhitelisted):
+            s3.list_buckets()
+
+        with pytest.raises(ServiceNotWhitelisted):
+            dynamodb.list_tables()
+
+    # Both are whitelisted, so both are allowed
+    with mock_aws(config={"core": {"service_whitelist": ["dynamodb", "s3"]}}):
+        s3.list_buckets()
+
+        dynamodb.list_tables()
diff --git a/tests/test_logs/test_export_tasks.py b/tests/test_logs/test_export_tasks.py
index dd29adbc0..97146899a 100644
--- a/tests/test_logs/test_export_tasks.py
+++ b/tests/test_logs/test_export_tasks.py
@@ -47,19 +47,6 @@ S3_POLICY = {
 }
 
 
-@pytest.fixture()
-def account_id():
-    if allow_aws_request:
-        identity = boto3.client("sts", region_name="us-east-1").get_caller_identity()
-        yield identity["Account"]
-    else:
-        with mock_aws():
-            identity = boto3.client(
-                "sts", region_name="us-east-1"
-            ).get_caller_identity()
-            yield identity["Account"]
-
-
 @pytest.fixture()
 def logs():
     if allow_aws_request:
diff --git a/tests/test_sqs/__init__.py b/tests/test_sqs/__init__.py
index e69de29bb..d2cf7d8a1 100644
--- a/tests/test_sqs/__init__.py
+++ b/tests/test_sqs/__init__.py
@@ -0,0 +1,50 @@
+from functools import wraps
+from uuid import uuid4
+
+import boto3
+
+from moto import mock_aws
+from tests import allow_aws_request
+
+
+def sqs_aws_verified():
+    """
+    Function that is verified to work against AWS.
+    Can be run against AWS at any time by setting:
+      MOTO_TEST_ALLOW_AWS_REQUEST=true
+
+    If this environment variable is not set, the function runs in a `mock_aws` context.
+
+    This decorator will:
+      - Create an SQS queue
+      - Run the test and pass the queue_name as an argument
+      - Delete the queue
+    """
+
+    def inner(func):
+        @wraps(func)
+        def pagination_wrapper(**kwargs):
+            queue_name = "q" + str(uuid4())[0:6]
+            kwargs["queue_name"] = queue_name
+
+            def create_queue_and_test():
+                client = boto3.client("sqs", region_name="us-east-1")
+
+                queue_url = client.create_queue(QueueName=queue_name)["QueueUrl"]
+                kwargs["queue_url"] = queue_url
+                try:
+                    resp = func(**kwargs)
+                finally:
+                    client.delete_queue(QueueUrl=queue_url)
+
+                return resp
+
+            if allow_aws_request():
+                return create_queue_and_test()
+            else:
+                with mock_aws():
+                    return create_queue_and_test()
+
+        return pagination_wrapper
+
+    return inner
diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py
index b6294ff82..7e5410d9f 100644
--- a/tests/test_sqs/test_sqs.py
+++ b/tests/test_sqs/test_sqs.py
@@ -23,6 +23,7 @@ from moto.sqs.models import (
 )
 from moto.utilities.distutils_version import LooseVersion
 from tests import aws_verified
+from tests.test_sqs import sqs_aws_verified
 
 TEST_POLICY = """
 {
@@ -278,6 +279,15 @@ def test_create_queue_with_policy():
     }
 
 
+@aws_verified
+@pytest.mark.aws_verified
+def test_get_unknown_queue_by_name():
+    sqs = boto3.resource("sqs", "us-east-1")
+    with pytest.raises(sqs.meta.client.exceptions.QueueDoesNotExist) as exc:
+        sqs.get_queue_by_name(QueueName="doesnotexist")
+    _verify_unknown_queue_error(exc)
+
+
 @mock_aws
 def test_set_queue_attribute_empty_policy_removes_attr():
     client = boto3.client("sqs", region_name=REGION)
@@ -355,37 +365,35 @@ def test_get_queue_url():
     assert q_name in response["QueueUrl"]
 
 
-@mock_aws
+@aws_verified
+@pytest.mark.aws_verified
 def test_get_queue_url_error_not_exists():
-    # given
     client = boto3.client("sqs", region_name=REGION)
+    sqs = boto3.resource("sqs", region_name=REGION)
 
-    # when
     with pytest.raises(ClientError) as e:
         client.get_queue_url(QueueName="not-exists")
+    _verify_unknown_queue_error(e)
 
-    # then
-    ex = e.value
-    assert ex.operation_name == "GetQueueUrl"
-    assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
-    assert "AWS.SimpleQueueService.NonExistentQueue" in ex.response["Error"]["Code"]
-    assert ex.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+    with pytest.raises(ClientError) as err:
+        sqs.Queue("http://whatever-incorrect-queue-address").load()
+    _verify_unknown_queue_error(err, "GetQueueAttributes")
 
 
-@mock_aws
-def test_get_nonexistent_queue():
-    sqs = boto3.resource("sqs", region_name=REGION)
+def _verify_unknown_queue_error(e, op_name="GetQueueUrl", status_code=400):
+    response = e.value.response
+    assert e.value.operation_name == op_name
+    assert response["ResponseMetadata"]["HTTPStatusCode"] == status_code
+    assert "AWS.SimpleQueueService.NonExistentQueue" == response["Error"]["Code"]
 
-    with pytest.raises(ClientError) as err:
-        sqs.Queue("http://whatever-incorrect-queue-address").load()
-    ex = err.value
-    assert ex.operation_name == "GetQueueAttributes"
-    assert ex.response["Error"]["Code"] == "AWS.SimpleQueueService.NonExistentQueue"
-    assert ex.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+    botocore_version = sys.modules["botocore"].__version__
+    if LooseVersion(botocore_version) >= LooseVersion("1.34.90"):
+        assert response["Error"]["Message"] == "The specified queue does not exist."
+    else:
+        assert (
+            response["Error"]["Message"]
+            == "The specified queue does not exist for this wsdl version."
+        )
 
 
 @mock_aws
@@ -742,22 +750,16 @@ def test_delete_queue():
     assert q_name not in [u[u.rfind("/") + 1 :] for u in all_urls]
 
 
-@mock_aws
-def test_delete_queue_error_not_exists():
+@aws_verified
+@pytest.mark.aws_verified
+def test_delete_queue_error_not_exists(account_id):
     client = boto3.client("sqs", region_name=REGION)
 
     with pytest.raises(ClientError) as e:
         client.delete_queue(
-            QueueUrl=f"https://queue.amazonaws.com/{ACCOUNT_ID}/not-exists"
+            QueueUrl=f"https://queue.amazonaws.com/{account_id}/unknown"
         )
-
-    ex = e.value
-    assert ex.operation_name == "DeleteQueue"
-    assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
-    assert "AWS.SimpleQueueService.NonExistentQueue" in ex.response["Error"]["Code"]
-    assert ex.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+    _verify_unknown_queue_error(e, op_name="DeleteQueue")
 
 
 @mock_aws
@@ -850,25 +852,20 @@ def test_get_queue_attributes_errors():
     assert client_error.value.response["Error"]["Message"] == "Unknown Attribute ."
 
 
-@mock_aws
-def test_get_queue_attributes_error_not_exists():
+@aws_verified
+@pytest.mark.aws_verified
+def test_get_queue_attributes_error_not_exists(account_id):
     # given
     client = boto3.client("sqs", region_name=REGION)
 
     # when
     with pytest.raises(ClientError) as e:
         client.get_queue_attributes(
-            QueueUrl=f"https://queue.amazonaws.com/{ACCOUNT_ID}/not-exists"
+            QueueUrl=f"https://queue.amazonaws.com/{account_id}/unknown"
         )
 
     # then
-    ex = e.value
-    assert ex.operation_name == "GetQueueAttributes"
-    assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
-    assert "AWS.SimpleQueueService.NonExistentQueue" in ex.response["Error"]["Code"]
-    assert ex.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+    _verify_unknown_queue_error(e, op_name="GetQueueAttributes")
 
 
 @mock_aws
@@ -1768,16 +1765,7 @@ def test_delete_message_errors():
     response = client.create_queue(QueueName=str(uuid4())[0:6])
     queue_url = response["QueueUrl"]
     client.send_message(QueueUrl=queue_url, MessageBody="body")
-    response = client.receive_message(QueueUrl=queue_url)
-    receipt_handle = response["Messages"][0]["ReceiptHandle"]
-
-    with pytest.raises(ClientError) as client_error:
-        client.delete_message(
-            QueueUrl=queue_url + "-not-existing", ReceiptHandle=receipt_handle
-        )
-    assert client_error.value.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+    client.receive_message(QueueUrl=queue_url)
 
     with pytest.raises(ClientError) as client_error:
         client.delete_message(QueueUrl=queue_url, ReceiptHandle="not-existing")
@@ -1787,6 +1775,18 @@ def test_delete_message_errors():
     )
 
 
+@aws_verified
+@pytest.mark.aws_verified
+def test_delete_message_from_unknown_url(account_id):
+    client = boto3.client("sqs", region_name=REGION)
+    with pytest.raises(ClientError) as client_error:
+        client.delete_message(
+            QueueUrl=f"https://sqs.us-east-1.amazonaws.com/{account_id}/unknown",
+            ReceiptHandle="unknown",
+        )
+    _verify_unknown_queue_error(client_error, op_name="DeleteMessage")
+
+
 @mock_aws
 def test_delete_message_twice_using_same_receipt_handle():
     client = boto3.client("sqs", region_name=REGION)
@@ -2037,21 +2037,17 @@ def test_message_attributes_in_receive_message():
     }
 
 
-@mock_aws
-def test_send_message_batch_errors():
+@sqs_aws_verified()
+@pytest.mark.aws_verified
+def test_send_message_batch_errors(queue_name=None, queue_url=None):
     client = boto3.client("sqs", region_name=REGION)
 
-    response = client.create_queue(QueueName="test-queue")
-    queue_url = response["QueueUrl"]
-
     with pytest.raises(ClientError) as client_error:
         client.send_message_batch(
             QueueUrl=queue_url + "-not-existing",
             Entries=[{"Id": "id_1", "MessageBody": "body_1"}],
         )
-    assert client_error.value.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+    _verify_unknown_queue_error(client_error, op_name="SendMessageBatch")
 
     with pytest.raises(ClientError) as client_error:
         client.send_message_batch(QueueUrl=queue_url, Entries=[])
@@ -2454,20 +2450,28 @@ def test_tags():
     assert client.list_queue_tags(QueueUrl=queue_url)["Tags"] == {"test1": "value1"}
 
 
-@mock_aws
-def test_list_queue_tags_errors():
+@aws_verified
+@pytest.mark.aws_verified
+def test_list_queue_tags_errors(account_id):
     client = boto3.client("sqs", region_name=REGION)
 
-    response = client.create_queue(
-        QueueName=str(uuid4())[0:6], tags={"tag_key_1": "tag_value_X"}
-    )
-    queue_url = response["QueueUrl"]
+    with pytest.raises(ClientError) as client_error:
+        client.list_queue_tags(
+            QueueUrl=f"https://sqs.us-east-1.amazonaws.com/{account_id}/not-existing"
+        )
+    _verify_unknown_queue_error(client_error, op_name="ListQueueTags")
+
 
+@aws_verified
+@pytest.mark.aws_verified
+def test_tag_unknown_queue(account_id):
+    client = boto3.client("sqs", region_name=REGION)
     with pytest.raises(ClientError) as client_error:
-        client.list_queue_tags(QueueUrl=queue_url + "-not-existing")
-    assert client_error.value.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
+        client.tag_queue(
+            QueueUrl=f"https://sqs.us-east-1.amazonaws.com/{account_id}/unknown",
+            Tags={"t": "v"},
+        )
+    _verify_unknown_queue_error(client_error, op_name="TagQueue")
 
 
 @mock_aws
@@ -2478,14 +2482,6 @@ def test_tag_queue_errors():
     response = client.create_queue(QueueName=q_name, tags={"tag_key_1": "tag_value_X"})
     queue_url = response["QueueUrl"]
 
-    with pytest.raises(ClientError) as client_error:
-        client.tag_queue(
-            QueueUrl=queue_url + "-not-existing", Tags={"tag_key_1": "tag_value_1"}
-        )
-    assert client_error.value.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
-
     with pytest.raises(ClientError) as client_error:
         client.tag_queue(QueueUrl=queue_url, Tags={})
     assert client_error.value.response["Error"]["Message"] == (
@@ -2505,6 +2501,18 @@ def test_tag_queue_errors():
     )
 
 
+@aws_verified
+@pytest.mark.aws_verified
+def test_untag_unknown_queue(account_id):
+    client = boto3.client("sqs", region_name=REGION)
+    with pytest.raises(ClientError) as client_error:
+        client.untag_queue(
+            QueueUrl=f"https://sqs.us-east-1.amazonaws.com/{account_id}/unknown",
+            TagKeys=["tag1"],
+        )
+    _verify_unknown_queue_error(client_error, op_name="UntagQueue")
+
+
 @mock_aws
 def test_untag_queue_errors():
     client = boto3.client("sqs", region_name=REGION)
@@ -2514,12 +2522,6 @@ def test_untag_queue_errors():
     )
     queue_url = response["QueueUrl"]
 
-    with pytest.raises(ClientError) as client_error:
-        client.untag_queue(QueueUrl=queue_url + "-not-existing", TagKeys=["tag_key_1"])
-    assert client_error.value.response["Error"]["Message"] == (
-        "The specified queue does not exist for this wsdl version."
-    )
-
     with pytest.raises(ClientError) as client_error:
         client.untag_queue(QueueUrl=queue_url, TagKeys=[])
     assert client_error.value.response["Error"]["Message"] == (