88# central entrypoint port for all LocalStack API endpoints
99DEFAULT_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 ] = {
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-
141127def 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
158144def 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+
171173def get_service_port (service : str ) -> Optional [int ]:
172174 ports = get_service_ports ()
173175 return ports .get (service )
0 commit comments