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-clientVerified import paths — ran on the pinned version, not inferred.
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.
Ensure `region: 'your-aws-region'` is explicitly included in the configuration object passed to `apigClientFactory.newClient()`.
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.
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.
Change `const apigClientFactory = require('aws-api-gateway-client');` to `const apigClientFactory = require('aws-api-gateway-client').default;`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).
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.