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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ You can pass the following environment variables to LocalStack:
started in different containers using docker-compose.
* `HOSTNAME_EXTERNAL`: Name of the host to expose the services externally (defaults to `localhost`).
This host is used, e.g., when returning queue URLs from the SQS service to the client.
* `<SERVICE>_PORT_EXTERNAL`: Number of the port to expose a specific service externally (defaults to service ports above)
This SQS_PORT_EXTERNAL, for example, is used when returning queue URLs from the SQS service to the client.
* `USE_SSL`: Whether to use `https://...` URLs with SSL encryption (defaults to `false`).
* `KINESIS_ERROR_PROBABILITY`: Decimal value between 0.0 (default) and 1.0 to randomly
inject `ProvisionedThroughputExceededException` errors into Kinesis API responses.
Expand Down
3 changes: 3 additions & 0 deletions localstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
backend_override_var = '%s_BACKEND' % key.upper().replace('-', '_')
if os.environ.get(backend_override_var):
CONFIG_ENV_VARS.append(backend_override_var)
port_external_override_var = '%s_PORT_EXTERNAL' % key.upper().replace('-', '_')
if os.environ.get(port_external_override_var):
CONFIG_ENV_VARS.append(port_external_override_var)

def in_docker():
""" Returns: True if running in a docker container, else False """
Expand Down
4 changes: 2 additions & 2 deletions localstack/services/sqs/sqs_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>

from localstack.utils.common import to_str
from localstack.utils.analytics import event_publisher
from localstack.services.generic_proxy import ProxyListener
Expand Down Expand Up @@ -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)

content_str = re.sub(r'<QueueUrl>\s*([a-z]+)://[^<]*:([0-9]+)/([^<]*)\s*</QueueUrl>',
r'<QueueUrl>\1://%s:%s/\3</QueueUrl>' % (HOSTNAME_EXTERNAL, external_port), content_str)
new_response._content = content_str
Expand Down