# @adastradev/aws-api-gateway-client 中文文档

规范地址：https://npmcn.com/package/%40adastradev/aws-api-gateway-client/

版本：2\.0\.16
npm 元数据更新时间：2026-09-30T21:58:51.221Z
中文译文更新时间：2026-11-06T09:26:59.683Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40adastradev/aws-api-gateway-client
原文对照：https://npmcn.com/package/%40adastradev/aws-api-gateway-client/?lang=original
项目主页：https://github.com/adastradev/aws-api-gateway-client#readme
源码仓库：https://github.com/adastradev/aws-api-gateway-client

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：93.3 kB，8 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：4 个
- 首次发布：2019-08-29T15:28:53.294Z
- 最新版本发布：2026-05-04T14:26:42.663Z
- 近 30 天下载量：3589（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：59（近 12 个月 3 个）

## 中文简介

AWS API 网关客户端的模块

## 安装

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

也可以使用：`pnpm add @adastradev/aws-api-gateway-client`、`yarn add @adastradev/aws-api-gateway-client`、`bun add @adastradev/aws-api-gateway-client`

## README

[![dependencies Status](https://david-dm.org/kndt84/aws-api-gateway-client/status.svg)](https://david-dm.org/kndt84/aws-api-gateway-client) [![Build Status](https://travis-ci.org/kndt84/aws-api-gateway-client.svg?branch=master)](https://travis-ci.org/kndt84/aws-api-gateway-client) [![npm](https://img.shields.io/npm/dm/aws-api-gateway-client.svg)](https://www.npmjs.com/package/aws-api-gateway-client)

# 概览

基于自动生成的JavaScript SDK的AWS API网关客户端模块. 此模块不仅可用于Node.js,也可用于前端. 此外,它还概括了原始SDK的端点特有方法.

参考:  
[https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html 页面存档备份,存于互联网档案馆](https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html)

# 先决条件

为了JavaScript SDK工作,你的API需要支持CORS. 亚马逊 API 网关开发者指南 解释如何 [为终点设置 CORS](https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html)。 。 。 .

# V1-V2少校弹出

在将轴从0.26.1更新到1.6.2的过程中,我们发现,使用滑稽测试的重置可能会遇到嘲弄的问题,因此如果你从消耗v1转向v2,请注意这一差异. 有关于一些共同问题和解决的共同文件.

# 安装

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

# 在您的工程中使用 SDK

需要模块

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

设定引用Url配置并创建客户端 。 如需授权,须提供补充资料,说明如下.

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

要求建立API的形式如下: 每个API呼叫返回一个承诺, 它引用成功和失败的回调

```
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
    });
```

# 使用 AWS IAM 进行授权

要以 AWS 证书初始化 SDK 使用下面的代码. 注意, 如果您使用证书, 所有对 API 的请求都会被签名 。 这意味着您将不得不为每个请求设置相应的 CORS 接受-\* 标题 .

```
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.
});
```

# 使用 API 密钥

要使用客户端 SDK 的 API 密钥, 您可以将密钥作为参数传递到 Factory 对象 。 注意, 如果您使用 apiKey , 它将作为标题“ x- api- key” 附加到 API 的所有请求上 。 这意味着您将不得不为每个请求设置相应的 CORS 接受-\* 标题 .

```
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 是什么？

AWS API 网关客户端的模块

### 如何安装 @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 和提交记录判断。

