@aws-sdk/config

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

Injectable dependencies, extensions, and other plugins for AWS SDK clients.

原始使用文档
文档目录10 节
  1. Table of Contents
  2. Usage
  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. Compile-time transforms
  10. Runtime Typecheck

@aws-sdk/config

NPM version NPM downloads

This package exports dependency implementations for configuring the AWS SDK for JavaScript v3 clients that may be used in your application code.

For an overview of configuration options on SDK clients, see supplemental-docs/CLIENTS.md.

Table of Contents

Usage

Install this alongside your SDK client packages(s) to access optional SDK plugins and injectable dependency implementations.

{
  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",
  },
}

The elements exported from this package are organized into submodules accessible by import paths.

@aws-sdk/config/credentials

This module includes the same API exported from @aws-sdk/credential-providers.

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

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

See @aws-sdk/credential-providers for the complete API.

See also CLIENTS.md#credentials.

@aws-sdk/config/logger

This module exports a helper for log level filtering.

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

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

See CLIENTS.md#logger for implementing your own logger.

@aws-sdk/config/protocol

This module exports a selection of AWS Protocols, which you can use for protocol selection override or extend to customize serialization behavior (advanced usage).

// 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 {},
});

See CLIENTS.md#protocol.

@aws-sdk/config/requestHandler

This module exports the two common HTTP request handler implementations for extension.

// 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);
    }
  })(),
});

See CLIENTS.md#requestHandler.

@aws-sdk/config/retryStrategy

This module exports the SDK retry strategy implementations. Please keep in mind that typically, you won't need to customize the retry behavior of the SDK, and that maxAttempts and retryMode can be configured with simple values that do not need imports.

See CLIENTS.md#retryStrategy.

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

This module exports compile-time type transform helpers and runtime typechecking components.

Compile-time transforms

For compile-time type transform helpers, see usage at @smithy/types.

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

Runtime Typecheck

Refer to SCHEMAS.md for an introduciton to how the SDK uses schemas to serialize and deserialize data structures. Schemas are also used by the runtime typecheck plugin.

// 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/071 天前
3.1163.02026/11/062 天前
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 是什么?

Injectable dependencies, extensions, and other plugins for AWS SDK clients.

如何安装 @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(1 天前);至今共发布 188 个版本,其中过去 12 个月发布了 188 个;首次发布于 2026/01/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。