@aws-cdk/cli-plugin-contract

中文文档
2.182.2发布于 2026/04/16Apache-2.0TypeScriptCommonJS零依赖构建来源已验证近 30 天下载 104.3万

Contract between the CLI and authentication plugins, for the exchange of AWS credentials

原始使用文档

AWS CDK CLI Library


cdk-constructs: Stable


Overview

As any piece of software that interacts with an AWS account, the CDK CLI needs AWS credentials for authentication and authorization. When it comes to choose which sources to get credentials from, it has the same behavior as the AWS CLI. But this basic behavior may result in some failure scenarios:

  • The initial set of credentials to work with cannot be obtained.
  • The account to which the initial credentials belong to cannot be obtained.
  • The account associated to the credentials is different from the account on which the CLI is trying to operate on.

Since these failures may happen for valid use case reasons, the CDK CLI offers an alternative mechanism for users to provide AWS credentials: credential provider plugins.

This package defines the types and the contract between the CLI and the plugins, which plugin authors are expected to adhere to.

The entrypoint is communicated to the CLI via the --plugin command line argument. The value of this argument should be a JavaScript file that, when require'd, will return an instance of the Plugin interface.

Once the CLI gets an instance of a plugin, it first initializes plugin by calling the Plugin.init() method, if one is defined. The CLI uses this method to pass an instance of IPluginHost to the plugin. The plugin, in turn, can use the repository to register one or more instances of CredentialProviderSource, which is where the actual logic for providing credentials is located.

If, in the authentication process, the CLI decides to use plugins, it will try each credential provider source in the order in which they were registered. For each source, the first thing the CLI will check is whether the source is ready to interact at all, by calling the isAvailable() method. If it is available, the next check is whether it can provide credentials for the specific account the CLI is targeting at that moment. This is the canProvideCredentials() method.

If both checks pass, the CLI asks the source for credentials by calling getProvider(). In addition to the account ID, this method also receives the Mode of operation, which can be ForReading or ForWriting. This information may be useful to tailor the credentials for the use case. For example, if the CLI needs the credentials only for reading, the plugin may return credentials with more restricted permissions.

版本与发布记录

@aws-cdk/cli-plugin-contract 共发布 18 个版本,首次发布于 2025/01/04;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.182.2latest2026/04/166 个月前
2.182.12026/01/289 个月前
2.182.02025/12/1110 个月前
2.181.12025/07/171.3 年前
2.181.02025/06/051.4 年前
2.180.22025/05/141.5 年前

关于 @aws-cdk/cli-plugin-contract 的常见问题

@aws-cdk/cli-plugin-contract 是什么?

Contract between the CLI and authentication plugins, for the exchange of AWS credentials

如何安装 @aws-cdk/cli-plugin-contract?

在项目目录运行 npm install @aws-cdk/cli-plugin-contract,或使用 pnpm add / yarn add / bun add。

@aws-cdk/cli-plugin-contract 支持 TypeScript 吗?

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

@aws-cdk/cli-plugin-contract 支持 ESM 还是 CommonJS?

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

@aws-cdk/cli-plugin-contract 需要什么版本的 Node.js?

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

@aws-cdk/cli-plugin-contract 可以商用吗?

@aws-cdk/cli-plugin-contract 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws-cdk/cli-plugin-contract 的下载量有多少?

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

@aws-cdk/cli-plugin-contract 还在维护吗?

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