@karmaniverous/aws-api-gateway-tools
    Preparing search index...

    AwsApiGatewayTools (programmatic API)

    This guide explains how to use AwsApiGatewayTools as a small, opinionated wrapper around AWS API Gateway (REST APIs).

    If you’re looking for the CLI or plugin behavior instead, see the aws api-gateway plugin guide.

    npm i @karmaniverous/aws-api-gateway-tools
    

    This package is ESM-only (Node >= 20).

    import { AwsApiGatewayTools } from '@karmaniverous/aws-api-gateway-tools';
    

    Create a configured instance (recommended usage):

    import { AwsApiGatewayTools } from '@karmaniverous/aws-api-gateway-tools';

    const tools = new AwsApiGatewayTools({
    clientConfig: {
    region: 'us-east-1',
    logger: console,
    },
    xray: 'auto',
    });

    new AwsApiGatewayTools({ ... }) accepts:

    • clientConfig?: APIGatewayClientConfig
      • Any AWS SDK v3 API Gateway client configuration (region, credentials, retry options, etc.).
      • If clientConfig.logger is provided, it must implement debug, info, warn, and error (the unified get-dotenv Logger contract). The wrapper validates this contract up front (it does not polyfill missing methods).
    • xray?: 'auto' | 'on' | 'off'
      • 'auto' (default): enable only when AWS_XRAY_DAEMON_ADDRESS is set.
      • 'on': force capture (requires AWS_XRAY_DAEMON_ADDRESS and aws-xray-sdk).
      • 'off': never enable capture.

    The instance exposes a few helpful properties:

    • tools.client: the effective APIGatewayClient (captured/instrumented when X-Ray is enabled)
    • tools.clientConfig: the effective config used to construct the base client
    • tools.logger: the validated console-like logger
    • tools.xray: { mode, enabled, daemonAddress? } reflecting the effective runtime decision

    When you need API Gateway APIs that aren’t wrapped by this package, use tools.client directly and import AWS SDK command classes as needed:

    import { GetRestApisCommand } from '@aws-sdk/client-api-gateway';
    import { AwsApiGatewayTools } from '@karmaniverous/aws-api-gateway-tools';

    const tools = new AwsApiGatewayTools({
    clientConfig: { region: 'us-east-1', logger: console },
    });

    const res = await tools.client.send(new GetRestApisCommand({ limit: 25 }));
    console.log(res.items?.length ?? 0);

    Flush a REST API stage cache by id:

    await tools.flushStageCache({ restApiId: 'abc123', stageName: 'dev' });
    

    Resolve REST API id by name and flush:

    const { apiId } = await tools.flushStageCacheByName({
    apiName: 'my-api',
    stageName: 'dev',
    });
    console.log('flushed', apiId);

    Retrieve API key values by key names (strict: missing/ambiguous keys throw):

    const values = await tools.getApiKeyValuesByNames({
    keyNames: ['my-api-key-a', 'my-api-key-b'],
    });
    console.log(values.join(', '));

    X-Ray capture is guarded:

    • Install the optional peer dependency if you want capture:
      • aws-xray-sdk
    • In 'auto' mode, capture is enabled only when AWS_XRAY_DAEMON_ADDRESS is set.
    • In 'auto' mode, if the daemon address is set but aws-xray-sdk is not installed, construction throws with a clear error message.