diff --git a/lambdas/catalog-updater/index.js b/lambdas/catalog-updater/index.js index b30b2c221..806baafab 100644 --- a/lambdas/catalog-updater/index.js +++ b/lambdas/catalog-updater/index.js @@ -176,6 +176,26 @@ function copyAnyMethod(api) { return api } +/** Fetches all usage plans, combining all pages into a single array. */ +async function getAllUsagePlans() { + // The maximum allowed value of `limit` is 500 according to + // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html#getUsagePlans-property + const defaultParams = {limit: 500} + + console.log('Fetching first page of usage plans') + let response = await exports.gateway.getUsagePlans(defaultParams).promise() + const usagePlans = response.items + + while (response.position) { + console.log(`Fetching next page of usage plans, at position=[${response.position}]`) + const nextParams = {...defaultParams, position: response.position} + response = await exports.gateway.getUsagePlans(nextParams).promise() + usagePlans.push(...response.items) + } + + return usagePlans +} + function buildCatalog(swaggerFiles, sdkGeneration) { console.log(`results: ${JSON.stringify(swaggerFiles, null, 4)}`) console.log(sdkGeneration) @@ -185,10 +205,9 @@ function buildCatalog(swaggerFiles, sdkGeneration) { generic: [] } - return exports.gateway.getUsagePlans({}).promise() - .then((result) => { - console.log(`usagePlans: ${JSON.stringify(result.items, null, 4)}`) - let usagePlans = result.items + return getAllUsagePlans() + .then(usagePlans => { + console.log(`usagePlans: ${JSON.stringify(usagePlans, null, 4)}`) for (let i = 0; i < usagePlans.length; i++) { catalog.apiGateway[i] = usagePlanToCatalogObject(usagePlans[i], swaggerFiles, sdkGeneration) } @@ -252,4 +271,4 @@ exports = module.exports = { gateway: new AWS.APIGateway(), handler, hash -} \ No newline at end of file +}