File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import {
22 APIGatewayClient ,
3- GetRestApisCommand ,
3+ RestApi ,
4+ paginateGetRestApis ,
45} from "@aws-sdk/client-api-gateway" ;
56import { API_NAME , AWS_REGION } from "../constants/api-constants" ;
67
78export default async function getRestApiGatewayBaseUrl ( ) : Promise < string > {
89 const region = AWS_REGION ;
910 const client = new APIGatewayClient ( { region } ) ;
1011
11- const apis = await client . send ( new GetRestApisCommand ( { } ) ) ;
12- const api = apis . items ?. find ( ( a ) => a . name === API_NAME ) ;
13-
14- if ( ! api ?. id ) throw new Error ( `API with name "${ API_NAME } " not found.` ) ;
12+ const api = await getApi ( API_NAME , client ) ;
1513
1614 return `https://${ api . id } .execute-api.${ region } .amazonaws.com/main` ;
1715}
16+
17+ async function getApi (
18+ apiName : string ,
19+ client : APIGatewayClient ,
20+ ) : Promise < RestApi > {
21+ for await ( const page of paginateGetRestApis ( { client } , { } ) ) {
22+ const filtered = page . items ?. filter ( ( api ) => api . name === apiName ) ;
23+ if ( filtered ?. length === 1 ) {
24+ return filtered [ 0 ] ;
25+ }
26+ }
27+ throw new Error ( `API with name "${ apiName } " not found.` ) ;
28+ }
You can’t perform that action at this time.
0 commit comments