# @aws-sdk/config 中文文档

规范地址：https://npmcn.com/package/%40aws-sdk/config/

版本：3\.1164\.0
npm 元数据更新时间：2026-11-06T20:15:53.688Z
中文译文更新时间：2026-11-07T14:01:12.452Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40aws-sdk/config
原文对照：https://npmcn.com/package/%40aws-sdk/config/?lang=original
项目主页：https://github.com/aws/aws-sdk-js-v3/tree/main/packages/config
源码仓库：https://github.com/aws/aws-sdk-js-v3

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

- 包体积（解压后）：36.1 kB，51 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.0\.0
- 运行依赖：9 个
- 首次发布：2026-01-22T20:00:03.501Z
- 最新版本发布：2026-11-06T20:15:53.506Z
- 近 30 天下载量：38397（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：188（近 12 个月 188 个）

## 中文简介

AWS SDK客户端的可注射依赖性,扩展等插件.

## 安装

```sh
npm install @aws-sdk/config
```

也可以使用：`pnpm add @aws-sdk/config`、`yarn add @aws-sdk/config`、`bun add @aws-sdk/config`

## README

# `@aws-sdk/config`

[![NPM version](https://img.shields.io/npm/v/@aws-sdk/config/latest.svg)](https://www.npmjs.com/package/@aws-sdk/config) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/config.svg)](https://www.npmjs.com/package/@aws-sdk/config)

此套件导出配置 JavaScript v3 的 AWS SDK 的依赖性执行 用于应用程序代码的客户端.

关于SDK客户端配置选项的概述, 见 [补充文件/文件](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md)。 。 。 .

## 目录

-   [使用量](https://npmcn.com/package/%40aws-sdk/config/#readme-usage)
-   [`@aws-sdk/config/credentials`](https://npmcn.com/package/%40aws-sdk/config/#readme-aws-sdkconfigcredentials)
-   [`@aws-sdk/config/logger`](https://npmcn.com/package/%40aws-sdk/config/#readme-aws-sdkconfiglogger)
-   [`@aws-sdk/config/protocol`](https://npmcn.com/package/%40aws-sdk/config/#readme-aws-sdkconfigprotocol)
-   [`@aws-sdk/config/requestHandler`](https://npmcn.com/package/%40aws-sdk/config/#readme-aws-sdkconfigrequesthandler)
-   [`@aws-sdk/config/retryStrategy`](https://npmcn.com/package/%40aws-sdk/config/#readme-aws-sdkconfigretrystrategy)
-   [`@aws-sdk/config/typecheck`](https://npmcn.com/package/%40aws-sdk/config/#readme-aws-sdkconfigtypecheck)
    -   [编译时间转换](https://npmcn.com/package/%40aws-sdk/config/#readme-compile-time-transforms)
    -   [运行时间类型检查](https://npmcn.com/package/%40aws-sdk/config/#readme-runtime-typecheck)

## 使用量

与您的 SDK 客户端软件包一起安装此选项以访问可选 SDK 插件和可注入 依赖性执行.

```json5
{
  name: "your-app",
  dependencies: {
    "@aws-sdk/client-s3": "<=3.x.y",
    // where 3.x.y is a version of your choosing.
    "@aws-sdk/client-dynamodb": "<=3.x.y",
    "@aws-sdk/config": "<=3.x.y",
  },
}
```

从此包输出的元素被组织成可被导入路径访问的子模块.

## `@aws-sdk/config/credentials`

此模块包括从 `@aws-sdk/credential-providers`。 。 。 .

```js
// example: credentials
import { fromIni } from "@aws-sdk/config/credentials";

new S3Client({
  credentials: fromIni(),
});
```

见 [@aws-sdk/证书提供者](https://www.npmjs.com/package/@aws-sdk/credential-providers) 为完整的API.

见 (单位:千美元) [证书](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#credentials-credentials)。 。 。 .

## `@aws-sdk/config/logger`

此模块会导出一个用于日志级别过滤的助手 .

```js
// example: logger
import { LogLevel } from "@aws-sdk/config/logger";

new S3Client({
  logger: new LogLevel("debug", console),
});
```

见 [(原始内容存档于2018-06-21) (英语). CLIENTS.md#logger](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#logger-logger) 执行自己的记录器.

## `@aws-sdk/config/protocol`

此模块导出一组 AWS 协议, 您可以用于协议选择 覆盖或扩展 自定义序列化行为(先进用法).

```js
// example: protocol selection.
import { CloudWatchClient } from "@aws-sdk/client-cloudwatch";
import { AwsSmithyRpcV2CborProtocol } from "@aws-sdk/config/protocol";

new CloudWatchClient({
  protocol: AwsSmithyRpcV2CborProtocol,
});
```

```js
// example: protocol extension.
import { AwsRestXmlProtocol } from "@aws-sdk/config/protocol";

new S3Client({
  protocol: class CustomAwsRestXmlProtocol extends AwsRestXmlProtocol {},
});
```

见 [CLIENTS.md# 议定书书](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#protocol-protocol)。 。 。 .

## `@aws-sdk/config/requestHandler`

此模块导出两个常见的 HTTP 请求处理器执行 用于扩展.

```js
// example: requestHandler extension.
import { NodeHttpHandler, FetchHttpHandler } from "@aws-sdk/config/requestHandler";

new S3Client({
  requestHandler: new (class extends NodeHttpHandler {
    async handle(request) {
      return super.handle(request);
    }
  })(),
});
```

见 [CLIENTS.md# 请求汉德勒](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#request-handler-requesthandler)。 。 。 .

## `@aws-sdk/config/retryStrategy`

此模块输出 SDK 重试策略执行 。 请记住 通常,你不需要自定义 SDK的再试验行为 `maxAttempts` 财务报告和审定财务报表 `retryMode` 可配置不需要导入的简单值.

见 [战略](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#retry-strategy-retrystrategy-retrymode-maxattempts)。 。 。 .

```js
// example: retryStrategy with custom backoff.
import { ConfiguredRetryStrategy } from "@aws-sdk/config/retryStrategy";

new S3Client({
  retryStrategy: new ConfiguredRetryStrategy(
    // attempts
    5,

    // backoff 1 additional second per attempt
    (attempt: number) => 500 + attempt * 1_000
  ),
});
```

## `@aws-sdk/config/typecheck`

此模块导出编译时间类型变换帮助器和运行时间类型检查组件 .

### 编译时间转换

编译时间类型变换帮助工具,请参见: [@ smith/ 类型](https://www.npmjs.com/package/@smithy/types)。 。 。 .

```ts
// example: type transformers.
import type { AssertiveClient, BrowserClient, NodeJsClient, UncheckedClient } from "@aws-sdk/config/typecheck";

// UncheckedClient makes output fields non-nullable.
// You should still perform type checks as you deem
// necessary, but the SDK will no longer prompt you
// with nullability errors.
const s3 = new S3({}) as UncheckedClient<S3>;

// this transform narrows the type of output streams to Node.js Readable.
const s3Nodejs = new S3Client({}) as NodeJsClient<S3Client>;

// this transform narrows the type of output streams to web ReadableStream.
const s3Browser = new S3Client({}) as BrowserClient<S3Client>;
```

### 运行时间类型检查

参见 [谢马斯·姆德](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/SCHEMAS.md) 用于内导体 到SDK如何使用schemas来序列化和去序列化数据结构. 斯克马斯也是 用于运行时类型检查插件.

```js
// example: runtime typecheck usage with SDK client
import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { getRuntimeTypecheckPlugin } from "@aws-sdk/config/typecheck";

const ddb = new DynamoDB();

ddb.middlewareStack.use(
  // requires AWS SDK v3.953.0+ for shape checking.
  // requires AWS SDK v3.969.0+ for required member checks.
  getRuntimeTypecheckPlugin({
    logger: console,
    // throw means stop execution,
    // other values correspond to logger channel.
    input: "throw" || "error" || "warn" || "info" || "debug",
  })
);

await ddb
  .getItem({
    Key: {
      id: {
        S: new Date("wrong type"),
      },
    },
  })
  .catch(console.error);

/*
Error: DynamoDBClient->GetItemCommand input validation:
        {}.TableName: is required.
        {}.Key["id"].S: expected string, got object.
<... stack trace ...>
 */

// standalone usage
import { GetItemInput$ } from "@aws-sdk/client-dynamodb";
import { validateSchema } from "@aws-sdk/config/typecheck";

const errors = validateSchema(GetItemInput$, {
  Key: {
    id: {
      S: new Date("wrong type"),
    },
  },
});

console.log(errors.join("\n"));

/*
{}.TableName: is required.
{}.Key["id"].S: expected string, got object.
 */
```

## 常见问题

### @aws-sdk/config 是什么？

AWS SDK客户端的可注射依赖性,扩展等插件\.

### 如何安装 @aws-sdk/config？

在项目目录运行 npm install @aws-sdk/config，或使用 pnpm add / yarn add / bun add。

### @aws-sdk/config 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @aws-sdk/config 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @aws-sdk/config 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @aws-sdk/config 可以商用吗？

@aws-sdk/config 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @aws-sdk/config 的下载量有多少？

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

### @aws-sdk/config 还在维护吗？

最新版本 3\.1164\.0 发布于 2026/11/07（今天）；至今共发布 188 个版本，其中过去 12 个月发布了 188 个；首次发布于 2026/01/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

