# @authhero/aws-adapter 中文文档

规范地址：https://npmcn.com/package/%40authhero/aws-adapter/

版本：1\.10\.0
npm 元数据更新时间：2026-11-05T14:41:36.528Z
中文译文更新时间：2026-11-08T01:18:20.050Z
软件包许可：AGPL-3\.0-only

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

原始 npm 页面：https://www.npmjs.com/package/%40authhero/aws-adapter
原文对照：https://npmcn.com/package/%40authhero/aws-adapter/?lang=original
项目主页：https://authhero.net/
源码仓库：https://github.com/sesamyab/authhero

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

- 包体积（解压后）：474 kB，56 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：5 个
- peer 依赖：hono ^4\.6\.8，@hono/zod-openapi ^1\.4\.0
- 首次发布：2025-12-17T22:13:43.033Z
- 最新版本发布：2026-11-05T14:41:36.171Z
- 近 30 天下载量：1939（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：150（近 12 个月 150 个）

## 中文简介

AWS DynamoDB为AuthHero的适配器. 这个适配器执行AuthHero数据适配器,使用Amazon DynamoDB作为存储后端.

## 安装

```sh
npm install @authhero/aws-adapter
```

也可以使用：`pnpm add @authhero/aws-adapter`、`yarn add @authhero/aws-adapter`、`bun add @authhero/aws-adapter`

## README

# @authhero/锯齿适应器

AWS DynamoDB为AuthHero的适配器. 这个适配器执行AuthHero数据适配器,使用Amazon DynamoDB作为存储后端.

## 特征

-   用于高效使用DynamomaDB的单表设计
-   与AWS Lambda和Cloudflare工人合作
-   具有完整类型脚本支持的类型安全

## 安装

```bash
npm install @authhero/aws-adapter
# or
pnpm add @authhero/aws-adapter
```

## 使用量

### 与 AWS 蓝巴达

```typescript
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import createAdapters from "@authhero/aws-adapter";

const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);

const adapters = createAdapters(docClient, {
  tableName: "authhero",
});
```

### 和云花岗工人

```typescript
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import createAdapters from "@authhero/aws-adapter";

// In Cloudflare Workers, you need to provide credentials explicitly
const client = new DynamoDBClient({
  region: env.AWS_REGION,
  credentials: {
    accessKeyId: env.AWS_ACCESS_KEY_ID,
    secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
  },
});
const docClient = DynamoDBDocumentClient.from(client);

const adapters = createAdapters(docClient, {
  tableName: "authhero",
});
```

## 表格设计

此适配器采用单表设计,并有以下关键结构: 1

| 实体 | PK 键 | 苏格兰 |
| --- | --- | --- |
| 租户 | `TENANT#{tenant_id}` | `TENANT` |
| 用户 | `TENANT#{tenant_id}` | `USER#{user_id}` |
| 会议 | `TENANT#{tenant_id}` | `SESSION#{session_id}` |
| 客户端 | `TENANT#{tenant_id}` | `CLIENT#{client_id}` |
| 连接 | `TENANT#{tenant_id}` | `CONNECTION#{connection_id}` |
| 代码 | `TENANT#{tenant_id}` | `CODE#{code_id}` |
| 密码 | `TENANT#{tenant_id}#USER#{user_id}` | `PASSWORD#{password_id}` |
| . | . | . |

### 全球二级指数

-   **GSI1 (英语)**: 供用户通过电子邮件查询
    
    -   GSI1PK: (英语) `TENANT#{tenant_id}#EMAIL#{email}`
    -   GSI1SK: (英语) `USER`
-   **GSI2 (英语)**:用于查询自定义域
    
    -   GSI2PK: (英语) `DOMAIN#{domain}`
    -   GSI2SK: (英语) `CUSTOM_DOMAIN`

## DynamoDB 表格设置

创建带有以下配置的 DynamomDB 表格 :

```json
{
  "TableName": "authhero",
  "KeySchema": [
    { "AttributeName": "PK", "KeyType": "HASH" },
    { "AttributeName": "SK", "KeyType": "RANGE" }
  ],
  "AttributeDefinitions": [
    { "AttributeName": "PK", "AttributeType": "S" },
    { "AttributeName": "SK", "AttributeType": "S" },
    { "AttributeName": "GSI1PK", "AttributeType": "S" },
    { "AttributeName": "GSI1SK", "AttributeType": "S" },
    { "AttributeName": "GSI2PK", "AttributeType": "S" },
    { "AttributeName": "GSI2SK", "AttributeType": "S" }
  ],
  "GlobalSecondaryIndexes": [
    {
      "IndexName": "GSI1",
      "KeySchema": [
        { "AttributeName": "GSI1PK", "KeyType": "HASH" },
        { "AttributeName": "GSI1SK", "KeyType": "RANGE" }
      ],
      "Projection": { "ProjectionType": "ALL" }
    },
    {
      "IndexName": "GSI2",
      "KeySchema": [
        { "AttributeName": "GSI2PK", "KeyType": "HASH" },
        { "AttributeName": "GSI2SK", "KeyType": "RANGE" }
      ],
      "Projection": { "ProjectionType": "ALL" }
    }
  ],
  "BillingMode": "PAY_PER_REQUEST"
}
```

## 许可证

麻省理工学院

## 常见问题

### @authhero/aws-adapter 是什么？

AWS DynamoDB为AuthHero的适配器\. 这个适配器执行AuthHero数据适配器,使用Amazon DynamoDB作为存储后端\.

### 如何安装 @authhero/aws-adapter？

在项目目录运行 npm install @authhero/aws-adapter，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：hono（^4\.6\.8）、@hono/zod-openapi（^1\.4\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @authhero/aws-adapter 支持 TypeScript 吗？

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

### @authhero/aws-adapter 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @authhero/aws-adapter 可以商用吗？

@authhero/aws-adapter 使用 AGPL-3\.0-only 许可。最严格的 Copyleft：除分发外，通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括，不构成法律意见，请以许可原文为准。

### @authhero/aws-adapter 的下载量有多少？

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

### @authhero/aws-adapter 还在维护吗？

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

