# @aws/bedrock-token-generator 中文文档

规范地址：https://npmcn.com/package/%40aws/bedrock-token-generator/

版本：1\.1\.0
npm 元数据更新时间：2025-07-24T18:58:29.633Z
中文译文更新时间：2026-11-07T10:10:29.466Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：97 kB，60 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=16\.0\.0
- 运行依赖：9 个
- 首次发布：2025-07-01T02:38:07.303Z
- 最新版本发布：2025-07-24T18:58:29.391Z
- 近 30 天下载量：3759317（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

为 AWS Bedrock API 认证生成短期无记名符号的轻量级库

## 安装

```sh
npm install @aws/bedrock-token-generator
```

也可以使用：`pnpm add @aws/bedrock-token-generator`、`yarn add @aws/bedrock-token-generator`、`bun add @aws/bedrock-token-generator`

## README

# JavaScript/ TypeScript 的 AWS Bedrock 托肯生成器

[![npm version](https://badge.fury.io/js/aws-bedrock-token-generator.svg)](https://badge.fury.io/js/aws-bedrock-token-generator) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://npmcn.com/package/%40aws/bedrock-token-generator/LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/) [![Node.js Version](https://img.shields.io/node/v/aws-bedrock-token-generator.svg)](https://nodejs.org/)

一个轻量级库,用于为AWS Bedrock API认证生成短期无记名符号.

## 特征

-   ✅ **简单 API**: 生成无记名符号的 Async 函数
-   ✅ **安全**: 使用 AWS SigV4 签名,可配置标志过期(最多12小时)
-   ✅ **AWS SDK 整合**: 与 AWS 证书提供者无缝合作
-   ✅ **轻巧**: 最小依赖,有重点的功能
-   ✅ **测试良好**:具有多种情景的单位综合测试
-   ✅ **类型脚本**: 完整类型定义,以便更好的IDE体验

## 安装

```bash
npm install @aws/bedrock-token-generator
```

## 快速启动

### 使用带有默认证书和区域提供者的托肯提供者

```typescript
import { getTokenProvider } from "@aws/bedrock-token-generator";

// Create a token provider that uses default credentials and region providers.
// You can configure it to use other credential providers.
const provideToken = getTokenProvider();

async function example() {
    
  const token = await provideToken();

  // Use the token for API calls. The token has a default expiration of 12 hour.
  // If the expiresInSeconds parameter is specified during token creation, the 
  // expiration can be configured up to a maximum of 12 hours. However, the actual 
  // token validity period will always be the minimum of the requested expiration 
  // time and the AWS credentials' expiry time
  console.log(`Bearer Token: ${token}`);
}
```

### 使用带有证书提供者和地区的托肯提供者

您可以找到支持的证书提供者 [这里](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-credential-providers/)。 。 。 .

```typescript
import { getTokenProvider } from "@aws/bedrock-token-generator";
import { fromTemporaryCredentials } from "@aws-sdk/credential-providers";

const provideToken = getTokenProvider({
  credentials: fromTemporaryCredentials({
    params: {
      RoleArn: "arn:aws:iam::123456789012:role/BedrockRole",
    },
  }),
  region: "us-east-1",
});

async function example() {
    
  const token = await provideToken();

  // Use the token for API calls. The token has a default expiration of 12 hour.
  // If the expiresInSeconds parameter is specified during token creation, the 
  // expiration can be configured up to a maximum of 12 hours. However, the actual 
  // token validity period will always be the minimum of the requested expiration 
  // time and the AWS credentials' expiry time
  console.log(`Bearer Token: ${token}`);
}
```

### 使用具有特定证书、区域和过期的托肯供应商

```typescript
import { getTokenProvider } from "@aws/bedrock-token-generator";

const credentials = {
  accessKeyId: "YOUR_ACCESS_KEY_ID",
  secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
  sessionToken: "YOUR_SESSION_TOKEN",
};

const provideToken = getTokenProvider({
  credentials,
  region: "us-east-1",
  expiresInSeconds: 7200,
});

async function example() {
  const token = await provideToken();

  // Use the token for API calls. The token has an expiration of 2 hour. However, the actual token validity period
  // will always be the minimum of the requested expiration time and the AWS credentials' expiry time
  console.log(`Bearer Token: ${token}`);
}
```

### 使用具有特定证书、区域和过期的无国籍函数

```typescript
import { getToken } from "@aws/bedrock-token-generator";

async function example() {
  const credentials = {
    accessKeyId: "YOUR_ACCESS_KEY_ID",
    secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
    sessionToken: "YOUR_SESSION_TOKEN",
  };

  const token = await getToken({
    credentials,
    region: "us-east-1",
    expiresInSeconds: 7200,
  });

  // Use the token for API calls. The token has an expiration of 2 hour. However, the actual token validity period
  // will always be the minimum of the requested expiration time and the AWS credentials' expiry time
  console.log(`Bearer Token: ${token}`);
}
```

## API 参考

-   [API 参考](https://npmcn.com/package/%40aws/bedrock-token-generator/apidocs/README.md) - 详细的API文档

## 调试格式

生成的符号遵循此格式 :

```
bedrock-api-key-<base64-encoded-presigned-url>&Version=1
```

-   **前缀**数字 : `bedrock-api-key-` 识别符号类型
-   **有效载荷**: 具有嵌入式证书的 Base64 编码前的 URL
-   **版本**数字 : `&Version=1` 未来兼容性
-   **过期**: 该令牌的默认到期时间为12小时. 如果在符号创建期间指定了过期的InSeconds参数,则过期的配置最多可达12小时. 但是,实际有效期限将永远是 成为所要求的到期时间和AWS证书到期时间的最小值.

## 安全考虑

-   **托肯过期**: 该令牌的默认到期时间为12小时. 如果在符号创建期间指定了过期的InSeconds参数,则过期的配置最多可达12小时. 但是,实际有效期限将永远是 成为所要求的到期时间和AWS证书到期时间的最小值。 信使一旦过期必须再次生成, 因为它不能被刷新或延长.
-   **安全存储**: 安全地存储令牌并避免记录它们
-   **证书管理**:尽可能使用IAM的作用和临时证书
-   **网络安全**: 发送令牌时始终使用 HTTPS
-   **最低特权原则**:确保基本证书具备最低要求的许可

## 所需资源

-   **节点.js**: 16.0.0 或较晚
-   **类型脚本**: 4.7.0或更晚(用于TypeScript用户)

## 发展

### 建立发展环境

```bash
# Clone the repository
git clone https://github.com/aws/aws-bedrock-token-generator-js.git
cd aws-bedrock-token-generator-js

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test
```

### 运行测试

```bash
# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run linter
npm run lint

# Format code
npm run format
```

## 捐款

我们欢迎捐款! 请看 [捐款额](https://npmcn.com/package/%40aws/bedrock-token-generator/CONTRIBUTING.md) 详细情况.

### 发展 工作流量

1.  **叉子存储器**
2.  **创建特性分支**数字 : `git checkout -b feature-name`
3.  **更改并添加测试**
4.  **运行测试**数字 : `npm test`
5.  **格式代码**数字 : `npm run format`
6.  **提交拉动请求**

## 支助

-   **文档**数字 : [AWS 贝德洛克文档](https://docs.aws.amazon.com/bedrock/)
-   **问题**数字 : [GitHub 问题](https://github.com/aws/aws-bedrock-token-generator-js/issues)
-   **AWS 支持**数字 : [AWS 支助中心](https://console.aws.amazon.com/support/)

## 许可证

这个项目根据Apache许可证2.0获得许可——见 [自由主义](https://npmcn.com/package/%40aws/bedrock-token-generator/LICENSE) 详细文件.

## 相关项目

-   [用于 JavaScript 的 AWS SDK](https://github.com/aws/aws-sdk-js-v3)
-   [AWS 用于 Java 的 Bedrock 托肯生成器](https://github.com/aws/aws-bedrock-token-generator-java)
-   [AWS 用于 Python 的 Bedrock 托肯生成器](https://github.com/aws/aws-bedrock-token-generator-python)
-   [AWS 贝德洛克文档](https://docs.aws.amazon.com/bedrock/)

## 更改日志

见 [变动情况](https://npmcn.com/package/%40aws/bedrock-token-generator/CHANGELOG.md) 用于列出更改和版本历史.

## 常见问题

### @aws/bedrock-token-generator 是什么？

为 AWS Bedrock API 认证生成短期无记名符号的轻量级库

### 如何安装 @aws/bedrock-token-generator？

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

### @aws/bedrock-token-generator 支持 TypeScript 吗？

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

### @aws/bedrock-token-generator 支持 ESM 还是 CommonJS？

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

### @aws/bedrock-token-generator 需要什么版本的 Node\.js？

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

### @aws/bedrock-token-generator 可以商用吗？

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

### @aws/bedrock-token-generator 的下载量有多少？

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

### @aws/bedrock-token-generator 还在维护吗？

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

