Repository: getmoto/moto

Issue:
SQS Queue URL is pointing to AWS
I'm trying to mock SQS using moto_server

Currently if you create SQS Queue, you get QueueUrl like this:

```
{
    "QueueUrl": "http://sqs.us-east-1.amazonaws.com/123456789012/<queue_name>"
}
```

An implementation of SQS client when it has only QueueName is as following:

1) url = client.getQueueUrl(QueueName=queue_name)
2) client.sendMessage(QueueUrl=url, MessageBody=body)

Problem is that client (SDK) with endpoint of moto_server sends getQueueUrl to mocked SQS but sendMessage request goes to non-mocked AWS (goes to sqs.us-east-1.amazonaws.com)

Would it make sense to have different URL returned by getQueueURL? Maybe the same one as request host?

SQS Queue URL is pointing to AWS
I'm trying to mock SQS using moto_server

Currently if you create SQS Queue, you get QueueUrl like this:

```
{
    "QueueUrl": "http://sqs.us-east-1.amazonaws.com/123456789012/<queue_name>"
}
```

An implementation of SQS client when it has only QueueName is as following:

1) url = client.getQueueUrl(QueueName=queue_name)
2) client.sendMessage(QueueUrl=url, MessageBody=body)

Problem is that client (SDK) with endpoint of moto_server sends getQueueUrl to mocked SQS but sendMessage request goes to non-mocked AWS (goes to sqs.us-east-1.amazonaws.com)

Would it make sense to have different URL returned by getQueueURL? Maybe the same one as request host?



Discussion:
I think that makes sense. Would be happy to accept a PR doing that.

I think that makes sense. Would be happy to accept a PR doing that.


Resolving patch:
diff --git a/moto/sqs/models.py b/moto/sqs/models.py
--- a/moto/sqs/models.py
+++ b/moto/sqs/models.py
@@ -180,9 +180,8 @@ def attributes(self):
             result[attribute] = getattr(self, camelcase_to_underscores(attribute))
         return result
 
-    @property
-    def url(self):
-        return "http://sqs.{0}.amazonaws.com/123456789012/{1}".format(self.region, self.name)
+    def url(self, request_url):
+        return "{0}://{1}/123456789012/{2}".format(request_url.scheme, request_url.netloc, self.name)
 
     @property
     def messages(self):
diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py
--- a/moto/sqs/responses.py
+++ b/moto/sqs/responses.py
@@ -1,4 +1,5 @@
 from __future__ import unicode_literals
+from six.moves.urllib.parse import urlparse
 
 from moto.core.responses import BaseResponse
 from moto.core.utils import camelcase_to_underscores
@@ -57,26 +58,29 @@ def call_action(self):
         return status_code, headers, body
 
     def create_queue(self):
+        request_url = urlparse(self.uri)
         queue_name = self.querystring.get("QueueName")[0]
         queue = self.sqs_backend.create_queue(queue_name, visibility_timeout=self.attribute.get('VisibilityTimeout'),
             wait_time_seconds=self.attribute.get('WaitTimeSeconds'))
         template = self.response_template(CREATE_QUEUE_RESPONSE)
-        return template.render(queue=queue)
+        return template.render(queue=queue, request_url=request_url)
 
     def get_queue_url(self):
+        request_url = urlparse(self.uri)
         queue_name = self.querystring.get("QueueName")[0]
         queue = self.sqs_backend.get_queue(queue_name)
         if queue:
             template = self.response_template(GET_QUEUE_URL_RESPONSE)
-            return template.render(queue=queue)
+            return template.render(queue=queue, request_url=request_url)
         else:
             return "", dict(status=404)
 
     def list_queues(self):
+        request_url = urlparse(self.uri)
         queue_name_prefix = self.querystring.get("QueueNamePrefix", [None])[0]
         queues = self.sqs_backend.list_queues(queue_name_prefix)
         template = self.response_template(LIST_QUEUES_RESPONSE)
-        return template.render(queues=queues)
+        return template.render(queues=queues, request_url=request_url)
 
     def change_message_visibility(self):
         queue_name = self._get_queue_name()
@@ -265,7 +269,7 @@ def receive_message(self):
 
 CREATE_QUEUE_RESPONSE = """<CreateQueueResponse>
     <CreateQueueResult>
-        <QueueUrl>{{ queue.url }}</QueueUrl>
+        <QueueUrl>{{ queue.url(request_url) }}</QueueUrl>
         <VisibilityTimeout>{{ queue.visibility_timeout }}</VisibilityTimeout>
     </CreateQueueResult>
     <ResponseMetadata>
@@ -275,7 +279,7 @@ def receive_message(self):
 
 GET_QUEUE_URL_RESPONSE = """<GetQueueUrlResponse>
     <GetQueueUrlResult>
-        <QueueUrl>{{ queue.url }}</QueueUrl>
+        <QueueUrl>{{ queue.url(request_url) }}</QueueUrl>
     </GetQueueUrlResult>
     <ResponseMetadata>
         <RequestId>470a6f13-2ed9-4181-ad8a-2fdea142988e</RequestId>
@@ -285,7 +289,7 @@ def receive_message(self):
 LIST_QUEUES_RESPONSE = """<ListQueuesResponse>
     <ListQueuesResult>
         {% for queue in queues %}
-            <QueueUrl>{{ queue.url }}</QueueUrl>
+            <QueueUrl>{{ queue.url(request_url) }}</QueueUrl>
         {% endfor %}
     </ListQueuesResult>
     <ResponseMetadata>


Test patch:
diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py
--- a/tests/test_sqs/test_sqs.py
+++ b/tests/test_sqs/test_sqs.py
@@ -71,7 +71,7 @@ def test_create_queues_in_multiple_region():
     list(west1_conn.list_queues()['QueueUrls']).should.have.length_of(1)
     list(west2_conn.list_queues()['QueueUrls']).should.have.length_of(1)
 
-    west1_conn.list_queues()['QueueUrls'][0].should.equal('http://sqs.us-west-1.amazonaws.com/123456789012/blah')
+    west1_conn.list_queues()['QueueUrls'][0].should.equal('https://us-west-1.queue.amazonaws.com/123456789012/blah')
 
 
 @mock_sqs
@@ -85,7 +85,7 @@ def test_get_queue_with_prefix():
 
     queue = conn.list_queues(QueueNamePrefix="test-")['QueueUrls']
     queue.should.have.length_of(1)
-    queue[0].should.equal("http://sqs.us-west-1.amazonaws.com/123456789012/test-queue")
+    queue[0].should.equal("https://us-west-1.queue.amazonaws.com/123456789012/test-queue")
 
 
 @mock_sqs