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

Skip to content

sqs: add ability to define the external port #1047

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

Merged
merged 1 commit into from
Dec 9, 2018
Merged
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 @@ -137,6 +137,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)
`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
6 changes: 6 additions & 0 deletions localstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# expose services on a specific host externally
HOSTNAME_EXTERNAL = os.environ.get('HOSTNAME_EXTERNAL', '').strip() or LOCALHOST

# expose SQS on a specific port externally
SQS_PORT_EXTERNAL = int(os.environ.get('SQS_PORT_EXTERNAL') or 0)

# name of the host under which the LocalStack services are available
LOCALSTACK_HOSTNAME = os.environ.get('LOCALSTACK_HOSTNAME', '').strip() or HOSTNAME

Expand Down Expand Up @@ -74,6 +77,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():
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
from localstack.utils.common import to_str, md5
from localstack.utils.analytics import event_publisher
from localstack.services.awslambda import lambda_api
Expand Down Expand Up @@ -91,7 +91,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 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