{"id":12860,"library":"aws-api-gateway-client","title":"AWS API Gateway Client","description":"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.","status":"maintenance","version":"0.3.7","language":"javascript","source_language":"en","source_url":"https://github.com/kndt84/aws-api-gateway-client","tags":["javascript","aws","apigateway"],"install":[{"cmd":"npm install aws-api-gateway-client","lang":"bash","label":"npm"},{"cmd":"yarn add aws-api-gateway-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add aws-api-gateway-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for implementing retry logic in API calls, configured via `retries` and `retryCondition` options.","package":"axios-retry","optional":false}],"imports":[{"note":"The library primarily exports a default factory function. Use a default import for ESM.","wrong":"import { apigClientFactory } from 'aws-api-gateway-client';","symbol":"apigClientFactory","correct":"import apigClientFactory from 'aws-api-gateway-client';"},{"note":"When using CommonJS `require`, access the `default` export to get the factory function.","wrong":"const apigClientFactory = require('aws-api-gateway-client');","symbol":"apigClientFactory","correct":"const apigClientFactory = require('aws-api-gateway-client').default;"},{"note":"While not a direct import, understanding the configuration object shape is crucial. Types are typically inferred or defined locally.","symbol":"Config","correct":"interface Config { invokeUrl: string; region?: string; accessKey?: string; secretKey?: string; sessionToken?: string; }"}],"quickstart":{"code":"import apigClientFactory from 'aws-api-gateway-client';\n\nconst config = {\n    invokeUrl: 'https://xxxxx.execute-api.us-east-1.amazonaws.com', // Replace with your API Gateway invoke URL\n    region: 'us-east-1', // REQUIRED: Specify your API's region\n    accessKey: process.env.AWS_ACCESS_KEY_ID ?? 'YOUR_ACCESS_KEY', // OPTIONAL: For IAM auth\n    secretKey: process.env.AWS_SECRET_ACCESS_KEY ?? 'YOUR_SECRET_KEY', // OPTIONAL: For IAM auth\n    sessionToken: process.env.AWS_SESSION_TOKEN ?? '', // OPTIONAL: For temporary credentials\n    retries: 3 // Example: Retry up to 3 times on failure\n};\n\nconst apigClient = apigClientFactory.newClient(config);\n\nconst pathParams = {\n    userId: '1234'\n};\nconst pathTemplate = '/users/{userId}/profile';\nconst method = 'GET';\nconst additionalParams = {\n    headers: {\n        'Content-Type': 'application/json'\n    },\n    queryParams: {\n        filter: 'active'\n    }\n};\nconst body = {}; // For GET, body is usually empty\n\napigClient.invokeApi(pathParams, pathTemplate, method, additionalParams, body)\n    .then(function(result){\n        console.log('API call successful:', result.data);\n    })\n    .catch(function(error){\n        console.error('API call failed:', error);\n    });\n","lang":"javascript","description":"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."},"warnings":[{"fix":"Ensure `region: 'your-aws-region'` is explicitly included in the configuration object passed to `apigClientFactory.newClient()`.","message":"The `region` parameter became a required configuration option when initializing the client. Earlier versions might have implicitly defaulted to `us-east-1`.","severity":"breaking","affected_versions":">=0.2.16"},{"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.","message":"When 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`).","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=0.2.17"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const apigClientFactory = require('aws-api-gateway-client');` to `const apigClientFactory = require('aws-api-gateway-client').default;`","cause":"Incorrect CommonJS `require` usage, not accessing the `default` export.","error":"TypeError: apigClientFactory.newClient is not a function"},{"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).","cause":"API Gateway endpoint is not correctly configured to allow Cross-Origin Resource Sharing (CORS) requests from your client's origin.","error":"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."},{"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.","cause":"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.","error":"Missing credentials in config"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null}