Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sqs: add ability to define the external port #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

sqs: add ability to define the external port #672

wants to merge 1 commit into from

Conversation

nemtsov
Copy link
Contributor

@nemtsov nemtsov commented Mar 20, 2018

First, thanks for your amazing work on localstack!

Please treat this as a start of a conversation rather than a full-featured PR. I'm not certain that this is the right direction and would love your feedback.

Motivation

The issue I'm having is that I'm running localstack behind a proxy, which is running on a specific host (which is covered by HOSTNAME_EXTERNAL, but is also on a different port from that of the proxy. So, when SQS returns the queue URL it returns the HOSTNAME_EXTERNAL that I set, but returns the local port and not the port that the client requests the proxy with.

[proxy:80] -> [localstack:4576] -> [elasticmq:4561]

What I've done at the moment, is I've set my SQS port to :80 (which is what my proxy wants). This works, but in my opinion is more of a workaround because any other service needs to return a URL pointing back to itself, I will not be able to also put it on :80 as it will be taken by SQS.

Proposed solution

So, the solution I'm proposing is to define a <SERVICE>_PORT_EXTERNAL and use that along with HOSTNAME_EXTERNAL. Alternatively (and if there are no plans to use HOSTNAME_EXTERNAL as a single external hostname for all services) we can change it to something like <SERVICE>_EXTERNAL_URI, which would be a host:port combination specific to a service.

@@ -60,7 +60,7 @@ def return_response(self, method, path, data, headers, response, request_handler
# return https://... if we're supposed to use SSL
content_str = re.sub(r'<QueueUrl>\s*http://', r'<QueueUrl>https://', content_str)
# expose external hostname:port
external_port = get_external_port(headers, request_handler)
external_port = SQS_PORT_EXTERNAL if SQS_PORT_EXTERNAL else get_external_port(headers, request_handler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: could be simplified to

external_port = SQS_PORT_EXTERNAL or get_external_port(headers, request_handler)

@@ -5,7 +5,7 @@
from six.moves.urllib.parse import urlencode
from requests.models import Request, Response
from localstack import config
from localstack.config import HOSTNAME_EXTERNAL
from localstack.config import HOSTNAME_EXTERNAL, SQS_PORT_EXTERNAL
Copy link
Member

@whummer whummer May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot import SQS_PORT_EXTERNAL here as it hasn't been exposed as a variable in config.py. This currently results in a failed build.

There are two options here:

  • Remove the import, and retrieve the value in line 63 via int(os.environ.get('SQS_PORT_EXTERNAL') or 0)
  • Expose the <SERVICE>_PORT_EXTERNAL variables in config.py, similar to PORT_<SERVICE>

@whummer
Copy link
Member

whummer commented May 1, 2018

Thanks for this PR @nemtsov - I added a comment related to the failed build.

@mberlanda
Copy link
Contributor

@nemtsov looks like you are almost there. It may be worth to rebase this or on master and implemented the couple of suggestions :)

@whummer
Copy link
Member

whummer commented Dec 8, 2018

@nemtsov Any updates on this PR? Would be great if we could get this feature merged. Thanks

@nemtsov
Copy link
Contributor Author

nemtsov commented Dec 8, 2018

Closing in favor of #1047

@nemtsov nemtsov closed this Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants