@aws-sdk/config

中文文档
3.1164.0发布于 2026/11/07Apache-2.0TypeScriptESM + CJS近 30 天下载 3.8万

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

中文使用文档
文档目录10 节
  1. 目录
  2. 使用量
  3. @aws-sdk/config/credentials
  4. @aws-sdk/config/logger
  5. @aws-sdk/config/protocol
  6. @aws-sdk/config/requestHandler
  7. @aws-sdk/config/retryStrategy
  8. @aws-sdk/config/typecheck
  9. 编译时间转换
  10. 运行时间类型检查

@aws-sdk/config

NPM version NPM downloads

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

关于SDK客户端配置选项的概述, 见 补充文件/文件。 。 。 .

目录

使用量

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

{
  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。 。 。 .

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

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

见 @aws-sdk/证书提供者 为完整的API.

见 (单位:千美元) 证书。 。 。 .

@aws-sdk/config/logger

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

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

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

见 (原始内容存档于2018-06-21) (英语). CLIENTS.md#logger 执行自己的记录器.

@aws-sdk/config/protocol

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

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

new CloudWatchClient({
  protocol: AwsSmithyRpcV2CborProtocol,
});
// example: protocol extension.
import { AwsRestXmlProtocol } from "@aws-sdk/config/protocol";

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

见 CLIENTS.md# 议定书书。 。 。 .

@aws-sdk/config/requestHandler

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

// 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# 请求汉德勒。 。 。 .

@aws-sdk/config/retryStrategy

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

见 战略。 。 。 .

// 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/ 类型。 。 。 .

// 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>;

运行时间类型检查

参见 谢马斯·姆德 用于内导体 到SDK如何使用schemas来序列化和去序列化数据结构. 斯克马斯也是 用于运行时类型检查插件.

// 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 共发布 188 个版本,首次发布于 2026/01/23;过去 12 个月发布了 188 个版本。

版本发布日期距今
3.1164.0latest2026/11/07今天
3.1163.02026/11/061 天前
3.1162.02026/11/052 天前
3.1161.02026/10/318 天前
3.1160.02026/10/309 天前
3.1159.02026/10/2910 天前

关于 @aws-sdk/config 的常见问题

@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 和提交记录判断。