Registry / aws / aws-api-gateway-client

aws-api-gateway-client

JSON →
library0.3.7jsnpmunverified

This module provides a generalized client for interacting with AWS API Gateway, based on the auto-generated JavaScript SDKs. It streamlines the process of making API calls by providing a unified `invokeApi` method, abstracting away endpoint-specific functions. The library is designed to work in both Node.js environments and front-end browser applications. As of version 0.3.7, it incorporates minor bug fixes and dependency updates, with releases appearing to be on a maintenance schedule, addressing issues as they arise rather than following a strict cadence. A key differentiator is its ability to generalize API calls and integrate retry mechanisms via `axios-retry`, offering more robust communication with API Gateway endpoints compared to a raw generated SDK. It requires proper CORS configuration on the API Gateway side for successful operation, particularly when using IAM authorization. The current stable version is 0.3.7.

npm install aws-api-gateway-client
INSTALL
IMPORT
SIG · AWS-API-GATEWAY-CL
A
aws-api-gateway-client
awsjavascriptv0.3.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

apigClientFactory
import apigClientFactory from 'aws-api-gateway-client';
import { apigClientFactory } from 'aws-api-gateway-client';
The library primarily exports a default factory function. Use a default import for ESM.
apigClientFactory
const apigClientFactory = require('aws-api-gateway-client').default;
const apigClientFactory = require('aws-api-gateway-client');
When using CommonJS `require`, access the `default` export to get the factory function.
Config
interface Config { invokeUrl: string; region?: string; accessKey?: string; secretKey?: string; sessionToken?: string; }
While not a direct import, understanding the configuration object shape is crucial. Types are typically inferred or defined locally.

Demonstrates how to initialize the API Gateway client, configure it with an invoke URL and credentials (if needed), and then perform a GET request to a parameterized path.

import apigClientFactory from 'aws-api-gateway-client'; const config = { invokeUrl: 'https://xxxxx.execute-api.us-east-1.amazonaws.com', // Replace with your API Gateway invoke URL region: 'us-east-1', // REQUIRED: Specify your API's region accessKey: process.env.AWS_ACCESS_KEY_ID ?? 'YOUR_ACCESS_KEY', // OPTIONAL: For IAM auth secretKey: process.env.AWS_SECRET_ACCESS_KEY ?? 'YOUR_SECRET_KEY', // OPTIONAL: For IAM auth sessionToken: process.env.AWS_SESSION_TOKEN ?? '', // OPTIONAL: For temporary credentials retries: 3 // Example: Retry up to 3 times on failure }; const apigClient = apigClientFactory.newClient(config); const pathParams = { userId: '1234' }; const pathTemplate = '/users/{userId}/profile'; const method = 'GET'; const additionalParams = { headers: { 'Content-Type': 'application/json' }, queryParams: { filter: 'active' } }; const body = {}; // For GET, body is usually empty apigClient.invokeApi(pathParams, pathTemplate, method, additionalParams, body) .then(function(result){ console.log('API call successful:', result.data); }) .catch(function(error){ console.error('API call failed:', error); });
Debug
Known issues
breakingThe `region` parameter became a required configuration option when initializing the client. Earlier versions might have implicitly defaulted to `us-east-1`.
fix
Ensure `region: 'your-aws-region'` is explicitly included in the configuration object passed to `apigClientFactory.newClient()`.
affects: >=0.2.16
gotchaWhen using AWS IAM for authorization, all requests made by the client are signed. This necessitates that your API Gateway endpoint and browser environment are correctly configured for Cross-Origin Resource Sharing (CORS), including appropriate `Access-Control-Allow-Headers` for the signing headers (e.g., `x-amz-date`, `authorization`).
fix
Refer to the AWS API Gateway developer guide on setting up CORS. Ensure your API Gateway integration responses include `Access-Control-Allow-Origin`, `Access-Control-Allow-Methods`, and `Access-Control-Allow-Headers` that permit the signed request headers.
affects: >=0.1.0
breakingThe library removed forceful `JSON.stringify` on the request body. If you were relying on the library to automatically stringify your body object, this behavior change could result in incorrect request payloads.
fix
Manually ensure that your `body` object is correctly stringified using `JSON.stringify(yourBodyObject)` if the API expects a JSON string, or send it in the format your API expects.
affects: >=0.2.17
Errors
Common errors & fixes
TypeError: apigClientFactory.newClient is not a function
Incorrect CommonJS `require` usage, not accessing the `default` export.
fix
Change `const apigClientFactory = require('aws-api-gateway-client');` to `const apigClientFactory = require('aws-api-gateway-client').default;`
Access to XMLHttpRequest at 'https://...' from origin 'http://localhost:...' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
API Gateway endpoint is not correctly configured to allow Cross-Origin Resource Sharing (CORS) requests from your client's origin.
fix
Configure CORS on your API Gateway resource and method. Ensure `Access-Control-Allow-Origin` header in the API Gateway's integration response is set to your client's origin (e.g., `*` for development, or specific domain in production).
Missing credentials in config
Attempting to make an authenticated API call without providing `accessKey` and `secretKey` (and optionally `sessionToken`) in the client configuration, or assuming a role without proper credentials.
fix
Provide `accessKey`, `secretKey`, and `sessionToken` (if using temporary credentials) in the `newClient` configuration object, or ensure your execution environment (e.g., EC2 instance profile, AWS Lambda role) has appropriate permissions and configured credentials.
Upgrade
Version history
0.3.7latest on npm
Audit
Dependencies
axios-retryrequiredUsed for implementing retry logic in API calls, configured via `retries` and `retryCondition` options.
Agent activity
67 hits · last 30 days
node
62
Amazon
1
OpenAI (training)
1
Resources
aws-api-gateway-client — npm install aws-api-gateway-client · libregistry