@aws/bedrock-token-generator

中文文档
1.1.0发布于 2025/07/25Apache-2.0TypeScriptCommonJS近 30 天下载 375.9万

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

中文使用文档
文档目录20 节
  1. 特征
  2. 安装
  3. 快速启动
  4. 使用带有默认证书和区域提供者的托肯提供者
  5. 使用带有证书提供者和地区的托肯提供者
  6. 使用具有特定证书、区域和过期的托肯供应商
  7. 使用具有特定证书、区域和过期的无国籍函数
  8. API 参考
  9. 调试格式
  10. 安全考虑
  11. 所需资源
  12. 发展
  13. 建立发展环境
  14. 运行测试
  15. 捐款
  16. 发展 工作流量
  17. 支助
  18. 许可证
  19. 相关项目
  20. 更改日志

JavaScript/ TypeScript 的 AWS Bedrock 托肯生成器

npm version License TypeScript Node.js Version

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

特征

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

安装

npm install @aws/bedrock-token-generator

快速启动

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

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}`);
}

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

您可以找到支持的证书提供者 这里。 。 。 .

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}`);
}

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

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}`);
}

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

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 参考

调试格式

生成的符号遵循此格式 :

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用户)

发展

建立发展环境

# 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

运行测试

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run linter
npm run lint

# Format code
npm run format

捐款

我们欢迎捐款! 请看 捐款额 详细情况.

发展 工作流量

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

支助

许可证

这个项目根据Apache许可证2.0获得许可——见 自由主义 详细文件.

更改日志

见 变动情况 用于列出更改和版本历史.

版本与发布记录

@aws/bedrock-token-generator 共发布 2 个版本,首次发布于 2025/07/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.0latest2025/07/251.3 年前
1.0.02025/07/011.4 年前

关于 @aws/bedrock-token-generator 的常见问题

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