Skip to content

Commit 0808483

Browse files
authored
consider AWS_ENDPOINT_URL configuration when resolving service endpoints (#46)
1 parent 14aadb3 commit 0808483

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# LocalStack Python Client Change Log
22

3+
* v2.1: Consider `AWS_ENDPOINT_URL` configuration when resolving service endpoints
34
* v2.0: Change `LOCALSTACK_HOSTNAME` from `<hostname>` to `<hostname>:<port>`; remove `EDGE_PORT` environment variable
45
* v1.39: Add endpoint for Amazon MQ
56
* v1.38: Add `enable_local_endpoints()` util function; slight project refactoring, migrate from `nose` to `pytests`

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ assert sqs.list_queues() is not None # list SQS in localstack
7070

7171
You can use the following environment variables for configuration:
7272

73-
* `LOCALSTACK_HOST`: A `<hostname>:<port>` variable defining where to find LocalStack (default: `localhost:4566`).
74-
* `USE_SSL`: Whether to use SSL when connecting to LocalStack (default: `False`).
73+
* `AWS_ENDPOINT_URL`: The endpoint URL to connect to (takes precedence over `USE_SSL`/`LOCALSTACK_HOST` below)
74+
* `LOCALSTACK_HOST` (deprecated): A `<hostname>:<port>` variable defining where to find LocalStack (default: `localhost:4566`).
75+
* `USE_SSL` (deprecated): Whether to use SSL when connecting to LocalStack (default: `False`).
7576

7677
### Enabling Transparent Local Endpoints
7778

localstack_client/config.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# central entrypoint port for all LocalStack API endpoints
99
DEFAULT_EDGE_PORT = 4566
1010

11+
# TODO: deprecated, remove!
1112
# NOTE: The ports listed below will soon become deprecated/removed, as the default in the
1213
# latest version is to access all services via a single "edge service" (port 4566 by default)
1314
_service_ports: Dict[str, int] = {
@@ -123,21 +124,6 @@
123124
_service_ports[key] = DEFAULT_EDGE_PORT
124125

125126

126-
def get_service_endpoint(
127-
service: str, localstack_host: Optional[str] = None
128-
) -> Optional[str]:
129-
"""
130-
Return the local endpoint URL for the given boto3 service (e.g., "s3").
131-
If $AWS_ENDPOINT_URL is configured in the environment, it is returned directly.
132-
Otherwise, the service endpoint is constructed from the dict of service ports (usually http://localhost:4566).
133-
"""
134-
env_endpoint_url = os.environ.get("AWS_ENDPOINT_URL", "").strip()
135-
if env_endpoint_url:
136-
return env_endpoint_url
137-
endpoints = get_service_endpoints(localstack_host=localstack_host)
138-
return endpoints.get(service)
139-
140-
141127
def parse_localstack_host(given: str) -> Tuple[str, int]:
142128
parts = given.split(":", 1)
143129
if len(parts) == 1:
@@ -156,6 +142,15 @@ def parse_localstack_host(given: str) -> Tuple[str, int]:
156142

157143

158144
def get_service_endpoints(localstack_host: Optional[str] = None) -> Dict[str, str]:
145+
"""
146+
Return the local endpoint URLs for the list of supported boto3 services (e.g., "s3", "lambda", etc).
147+
If $AWS_ENDPOINT_URL is configured in the environment, it is returned directly. Otherwise,
148+
the service endpoint is constructed from the dict of service ports (usually http://localhost:4566).
149+
"""
150+
env_endpoint_url = os.environ.get("AWS_ENDPOINT_URL", "").strip()
151+
if env_endpoint_url:
152+
return {key: env_endpoint_url for key in _service_ports.keys()}
153+
159154
if localstack_host is None:
160155
localstack_host = os.environ.get(
161156
"LOCALSTACK_HOST", f"localhost:{DEFAULT_EDGE_PORT}"
@@ -168,6 +163,13 @@ def get_service_endpoints(localstack_host: Optional[str] = None) -> Dict[str, st
168163
return {key: f"{protocol}://{hostname}:{port}" for key in _service_ports.keys()}
169164

170165

166+
def get_service_endpoint(
167+
service: str, localstack_host: Optional[str] = None
168+
) -> Optional[str]:
169+
endpoints = get_service_endpoints(localstack_host=localstack_host)
170+
return endpoints.get(service)
171+
172+
171173
def get_service_port(service: str) -> Optional[int]:
172174
ports = get_service_ports()
173175
return ports.get(service)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = localstack-client
3-
version = 2.0
3+
version = 2.1
44
url = https://github.com/localstack/localstack-python-client
55
author = LocalStack Team
66
author_email = info@localstack.cloud

0 commit comments

Comments
 (0)