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';
new AwsApiGatewayTools(...)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
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 clienttools.logger: the validated console-like loggertools.xray: { mode, enabled, daemonAddress? } reflecting the effective runtime decisionWhen 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);
flushStageCache(...)Flush a REST API stage cache by id:
await tools.flushStageCache({ restApiId: 'abc123', stageName: 'dev' });
flushStageCacheByName(...)Resolve REST API id by name and flush:
const { apiId } = await tools.flushStageCacheByName({
apiName: 'my-api',
stageName: 'dev',
});
console.log('flushed', apiId);
getApiKeyValuesByNames(...)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:
aws-xray-sdk'auto' mode, capture is enabled only when AWS_XRAY_DAEMON_ADDRESS is set.'auto' mode, if the daemon address is set but aws-xray-sdk is not installed, construction throws with a clear error message.aws api-gateway flush-cache|pull-keys), see the aws api-gateway plugin guide.