Options
All
  • Public
  • Public/Protected
  • All
Menu

Module paginate

Semi-Automated or manually-configurable pagination for AWS API calls

remarks

THIS MODULE IS DEPRECATED BY get-aws-results

This module makes use only of AWS SDKv2 Promises, but uses as much information as possible from the SDK to attempt to automatically paginate API calls using an async generator. It also provides the means to automatically paginate based on manually-provided values for the inputToken, outputToken and resultKey parameters.

This has been deprecated by a new approach in get-aws-results that uses the automatic pagination capabilities of the AWS SDKv2 that are hidden beneath the surface, using event listeners on AWS Request objects to recursively request additional pages.

deprecated

by get-aws-results

Index

Type aliases

PaginatableFunction

PaginatableFunction: (paginationTokenValueForRequest: string | undefined) => Promise<PaginatableResult>

Type declaration

    • Parameters

      • paginationTokenValueForRequest: string | undefined

      Returns Promise<PaginatableResult>

Functions

Const getPaginatedResults

  • Pagination implementation function for paginating AWS API Call results

    remarks

    A helper function for getting paginated results from AWS API calls. Most APIs return a maximum number of results, and a pagination token to allow to you make another call for the next set of results until no results remain. Additionally many APIs use different parameters for the pagination token such as nextToken or NextToken. This function allows us to make a generic API call, defining the correct pagination token for the API call, and retrieving all of the results

    example
    const AWS = require('aws-sdk');
    const client = new AWS.<client name>({<params>})();          // e.g. Organizations
    const operation = '<operation name>'                         // e.g. listAccounts
    paginationSettings = {
      inputToken: <the inputToken for the Operation>,            // e.g. NextToken
      outputToken: <the outputToken for the Operation>,          // e.g. NextToken
      resultKey: <the resultKey for the Operation>,              // e.g. Accounts
      moreResults: <Optional moreResults key for the Operation>, // e.g. IsTruncated
    }
    const res = await getPaginatedResults(async (paginationTokenValueForRequest) => {
      const operationParams = Object.assign({ [paginationSettings.inputToken]: paginationTokenValueForRequest }, params);
      //console.log(`Paginating\n\tclient: ${client.api.serviceId}\n\toperation: ${operation}\n\tparams: ${JSON.stringify(operationParams, null, 2)}\n\tpaginationSettings: ${JSON.stringify(paginationSettings, null, 2)}`);
      const page = await client[operation](operationParams).promise();
    
      return {
        paginationTokenValueFromResultsPage: page[paginationSettings.outputToken],
        resultsFromPage: page[paginationSettings.resultKey],
        moreResults: paginationSettings.moreResults ? page[paginationSettings.moreResults] : undefined,
      };
    });
    return { [paginationSettings.resultKey]: res };
    

    Parameters

    • awsApiCallerFunction: PaginatableFunction

      An async function, per the example, handling paginationTokenValueForRequest, and returning paginationTokenValueFromResultsPage, resultsFromPage, moreResults, to be called by this generator so as to yield a concatenation of all of the resultsFromPage

    Returns Promise<any[]>

    A promise to generate the concatenated results from each page generated by the function provided

Const paginate

  • A wrapper function for getPaginatedResults to simplify and standardise paginated AWS API calls

    remarks

    A function to make use of getPaginatedResults in a simple to use and standardised way. It accepts a configuration containing the AWS API Service and Operation to call, as well as optionally custom operation parameters, and custom pagination settings and tries to return paginated results for the call, either using the settings provided or automatically via information ascertained from the AWS API; or unpaginated if instructed or unable.

    example
    const aws = require('aws-sdk');
    const paginationConfig = {
      client: new aws.<aws service>(<{params}>), // e.g. Route53
      operation: '<operation>',                  // e.g. listHostedZones
      paginationSettings: {
        inputToken: '<operation input token>',   // e.g. NextToken
        outputToken: '<operation output token>', // e.g. NextToken
        resultKey: '<operation result key>',     // e.g. HostedZones
      },
    };
    const results = await paginate(paginationConfig);
    console.log(JSON.stringify(results, null, 2));
    

    Parameters

    • config: PaginationConfig

      The pagination config Object, containing the AWS Service Interface object, the operation to perform and optional parameters and pagination settings

    Returns Promise<any>

    A promise to return the AWS API call results, either constructed through pagination or generated as a single call to the API

Generated using TypeDoc