@adastradev/aws-api-gateway-client

中文文档
2.0.16发布于 2026/05/04MITCommonJS近 30 天下载 3589

A module for AWS API Gateway client

原始使用文档

dependencies Status Build Status npm

Overview

A module for AWS API gateway client based on auto-generated JavaScript SDK. This module can be used not only for Node.js but for front-end. In addition, it generalizes original SDK's endpoint specific methods.

Reference:
https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html

Prerequisites

For the JavaScript SDK to work your APIs need to support CORS. The Amazon API Gateway developer guide explains how to setup CORS for an endpoint.

Major Bump from V1-V2

In updating axios from 0.26.1 to 1.6.2 we found that repos using jest tests might experience issues with mocking so if you move from consuming v1 to v2 please note that difference. There is confluence documentation covering some common issues and fixes.

Install

npm install @adastradev/aws-api-gateway-client

Use the SDK in your project

Require module

var apigClientFactory = require('aws-api-gateway-client').default;

Set invokeUrl to config and create a client. For authorization, additional information is required as explained below.

config = {invokeUrl:'https://xxxxx.execute-api.us-east-1.amazonaws.com'}
var apigClient = apigClientFactory.newClient(config);

Calls to an API take the form outlined below. Each API call returns a promise, that invokes either a success and failure callback

var pathParams = {
    //This is where path request params go. 
    userId: '1234',
};
// Template syntax follows url-template https://www.npmjs.com/package/url-template
var pathTemplate = '/users/{userID}/profile'
var method = 'GET';
var additionalParams = {
    //If there are query parameters or headers that need to be sent with the request you can add them here
    headers: {
        param0: '',
        param1: ''
    },
    queryParams: {
        param0: '',
        param1: ''
    }
};
var body = {
    //This is where you define the body of the request
};

apigClient.invokeApi(pathParams, pathTemplate, method, additionalParams, body)
    .then(function(result){
        //This is where you would put a success callback
    }).catch( function(result){
        //This is where you would put an error callback
    });

Using AWS IAM for authorization

To initialize the SDK with AWS Credentials use the code below. Note, if you use credentials all requests to the API will be signed. This means you will have to set the appropiate CORS accept-* headers for each request.

var apigClient = apigClientFactory.newClient({
    invokeUrl:'https://xxxxx.execute-api.us-east-1.amazonaws.com', // REQUIRED
    
    region: 'eu-west-1',                                           // REQUIRED: The region where the API is deployed.
    
    accessKey: 'ACCESS_KEY',                                       // REQUIRED
    
    secretKey: 'SECRET_KEY',                                       // REQUIRED

    sessionToken: 'SESSION_TOKEN',                                 // OPTIONAL: If you are using temporary credentials
                                                                                you must include the session token.
    
    systemClockOffset: 0,                                          // OPTIONAL: An offset value in milliseconds to apply to signing time
    
    retries: 4,                                                    // OPTIONAL: Number of times to retry before failing. Uses axios-retry plugin.
    
    retryCondition: (err) => {                                     // OPTIONAL: Callback to further control if request should be retried.
      return err.response && err.response.status === 500;          //           Uses axios-retry plugin.
    },
    
    retryDelay: 100 || 'exponential' || (retryCount, error) => {   // OPTIONAL: Define delay (in ms) as a number, a callback, or
      return retryCount * 100                                      //           'exponential' to use the in-built exponential backoff
    }                                                              //           function. Uses axios-retry plugin. Default is no delay.
});

Using API Keys

To use an API Key with the client SDK you can pass the key as a parameter to the Factory object. Note, if you use an apiKey it will be attached as the header 'x-api-key' to all requests to the API will be signed. This means you will have to set the appropiate CORS accept-* headers for each request.

var apigClient = apigClientFactory.newClient({
    invokeUrl:'https://xxxxx.execute-api.us-east-1.amazonaws.com', // REQUIRED
    apiKey: 'API_KEY', // REQUIRED
    region: 'eu-west-1' // REQUIRED
});

版本与发布记录

@adastradev/aws-api-gateway-client 共发布 59 个版本,首次发布于 2019/08/29;过去 12 个月发布了 3 个版本。

版本发布日期距今
2.0.16latest2026/05/046 个月前
2.0.152026/01/089 个月前
2.0.142026/01/089 个月前
2.0.132025/09/241.1 年前
2.0.122025/08/051.3 年前
2.0.12-beta.1754334498618beta2025/08/051.3 年前

关于 @adastradev/aws-api-gateway-client 的常见问题

@adastradev/aws-api-gateway-client 是什么?

A module for AWS API Gateway client

如何安装 @adastradev/aws-api-gateway-client?

在项目目录运行 npm install @adastradev/aws-api-gateway-client,或使用 pnpm add / yarn add / bun add。

@adastradev/aws-api-gateway-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adastradev__aws-api-gateway-client 是否存在。

@adastradev/aws-api-gateway-client 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adastradev/aws-api-gateway-client 可以商用吗?

@adastradev/aws-api-gateway-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adastradev/aws-api-gateway-client 的下载量有多少?

根据 npm 官方下载统计,@adastradev/aws-api-gateway-client 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,589 次,日均约 120 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adastradev/aws-api-gateway-client 还在维护吗?

最新版本 2.0.16 发布于 2026/05/04(6 个月前);至今共发布 59 个版本,其中过去 12 个月发布了 3 个;首次发布于 2019/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。