1
- import { Provider , UrlParser , Endpoint } from "@aws-sdk/types" ;
1
+ import {
2
+ Provider ,
3
+ UrlParser ,
4
+ Endpoint ,
5
+ RegionInfoProvider ,
6
+ RegionInfo
7
+ } from "@aws-sdk/types" ;
2
8
3
9
export function normalizeEndpoint (
4
10
endpoint ?: string | Endpoint | Provider < Endpoint > ,
@@ -20,20 +26,15 @@ export interface EndpointsInputConfig {
20
26
*/
21
27
endpoint ?: string | Endpoint | Provider < Endpoint > ;
22
28
23
- /**
24
- * The endpoint provider to call if no endpoint is provided
25
- */
26
- endpointProvider ?: any ;
27
-
28
29
/**
29
30
* Whether TLS is enabled for requests.
30
31
*/
31
32
tls ?: boolean ;
32
33
}
33
34
interface PreviouslyResolved {
35
+ regionInfoProvider : RegionInfoProvider ;
34
36
urlParser : UrlParser ;
35
37
region : Provider < string > ;
36
- service : string ;
37
38
}
38
39
export interface EndpointsResolvedConfig
39
40
extends Required < EndpointsInputConfig > {
@@ -43,18 +44,21 @@ export function resolveEndpointsConfig<T>(
43
44
input : T & EndpointsInputConfig & PreviouslyResolved
44
45
) : T & EndpointsResolvedConfig {
45
46
const tls = input . tls || true ;
46
- const defaultProvider = ( tls : boolean , region : string ) => ( {
47
- protocol : tls ? "https:" : "http:" ,
48
- path : "/" ,
49
- hostname : `${ input . service } .${ region } .amazonaws.com`
50
- } ) ;
51
- const endpointProvider = input . endpointProvider || defaultProvider ;
52
47
const endpoint : Provider < Endpoint > = input . endpoint
53
48
? normalizeEndpoint ( input . endpoint , input . urlParser )
54
- : ( ) => input . region ( ) . then ( region => endpointProvider ( tls , region ) ) ;
49
+ : ( ) =>
50
+ input . region ( ) . then ( async region => {
51
+ const hostname = (
52
+ ( await input . regionInfoProvider ( region ) ) || ( { } as RegionInfo )
53
+ ) . hostname ;
54
+ if ( ! hostname )
55
+ throw new Error ( "Cannot resolve hostname from client config" ) ;
56
+ const endpoint = input . urlParser ( hostname ) ;
57
+ endpoint . protocol = tls ? "https:" : "http:" ;
58
+ return endpoint ;
59
+ } ) ;
55
60
return {
56
61
...input ,
57
- endpointProvider,
58
62
endpoint,
59
63
tls
60
64
} ;
0 commit comments