Skip to content

Commit 828d91c

Browse files
Fix get API for component tests
1 parent 63bd2f7 commit 828d91c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
import {
22
APIGatewayClient,
3-
GetRestApisCommand,
3+
RestApi,
4+
paginateGetRestApis,
45
} from "@aws-sdk/client-api-gateway";
56
import { API_NAME, AWS_REGION } from "../constants/api-constants";
67

78
export 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+
}

0 commit comments

Comments
 (0)