# @aws-cdk/aws-neptune-alpha 中文文档

规范地址：https://npmcn.com/package/%40aws-cdk/aws-neptune-alpha/

版本：2\.275\.0-alpha\.0
npm 元数据更新时间：2026-10-26T19:19:36.672Z
中文译文更新时间：2026-11-07T13:48:23.748Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：677 kB，24 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>= 20\.0\.0
- 运行依赖：0 个
- peer 依赖：constructs ^10\.5\.0，aws-cdk-lib ^2\.275\.0
- 首次发布：2021-10-13T18:38:38.504Z
- 最新版本发布：2026-10-26T19:19:35.650Z
- 近 30 天下载量：53533（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：380（近 12 个月 64 个）

## 中文简介

AWS: Neptune 的 CDK 构造库

## 安装

```sh
npm install @aws-cdk/aws-neptune-alpha
```

也可以使用：`pnpm add @aws-cdk/aws-neptune-alpha`、`yarn add @aws-cdk/aws-neptune-alpha`、`bun add @aws-cdk/aws-neptune-alpha`

## README

# 亚马逊海王星构造库

* * *

![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)

> 本单元中更高层次的构件的API是实验性的并正在积极开发中. 在今后任何版本中,它们都须作非背向相容的修改或去除。 这些是 不适用 [语义版本](https://semver.org/) 模型和断开的更改 在发行笔记中宣布. 这意味着虽然你可能使用它们,但可能需要更新 当更新到此软件包的更新版本时,您的源代码.

* * *

亚马逊 Neptune是一个快速,可靠,完全管理的图数据库服务,它使得与高度连接的数据集一起工作的应用程序易于构建和运行. 海王星的核心是一个目的建造的高性能图数据库引擎. 此引擎被优化,用于存储数十亿个关系,并用毫秒的耐用来查询图. Neptune支持流行的图查询语言Apache TinkerPop Gremlin和W3C的SPARQL,使您能够构建能高效地导航高连接数据集的查询.

这个 `@aws-cdk/aws-neptune-alpha` 软件包包含用于建立海王星数据库集群和实例的原始数据.

```ts
import * as neptune from '@aws-cdk/aws-neptune-alpha';
```

## 启动海王星数据库

为了建立海王星数据库,定义 `DatabaseCluster`您必须在 VPC 中启动数据库 .

```ts
const cluster = new neptune.DatabaseCluster(this, 'Database', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
});
```

默认情况下, 只能提供写家实例 .

## 连接中

要控制谁可以访问集群,请使用 `.connections` 属性。 海王星数据库有一个默认的端口,所以 您不需要指定端口 :

```ts
cluster.connections.allowDefaultPortFromAnyIpv4('Open to the world');
```

访问您数据库集群的终点将作为 `.clusterEndpoint` 财务报告和审定财务报表 `.clusterReadEndpoint` 属性 :

```ts
const writeAddress = cluster.clusterEndpoint.socketAddress;   // "HOSTNAME:PORT"
```

## IAM 认证

也可以使用 AWS 身份和访问管理(IAM) 数据库认证认证到数据库集群; 见 [https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth.html 互联网档案馆的存檔,存档日期2013-12-22](https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth.html) 需要更多信息和所支持的列表 版本和限制.

以下例子显示可以对数据库集群进行IAM认证,并允许连接访问IAM角色.

```ts
const cluster = new neptune.DatabaseCluster(this, 'Cluster', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  iamAuthentication: true, // Optional - will be automatically set if you call grantConnect() or grant().
});
const role = new iam.Role(this, 'DBRole', { assumedBy: new iam.AccountPrincipal(this.account) });
// Use one of the following statements to grant the role the necessary permissions
cluster.grantConnect(role); // Grant the role neptune-db:* access to the DB
cluster.grant(role, 'neptune-db:ReadDataViaQuery', 'neptune-db:WriteDataViaQuery'); // Grant the role the specified actions to the DB
```

## 自定义参数

Neptune允许通过提供自定义参数组来配置数据库行为. 详情请参见: 以下链接 : [https://docs.aws.amazon.com/neptune/latest/userguide/parameters.html 页面存档备份,存于互联网档案馆](https://docs.aws.amazon.com/neptune/latest/userguide/parameters.html)

```ts
const clusterParams = new neptune.ClusterParameterGroup(this, 'ClusterParams', {
  description: 'Cluster parameter group',
  parameters: {
    neptune_enable_audit_log: '1'
  },
});

const dbParams = new neptune.ParameterGroup(this, 'DbParams', {
  description: 'Db parameter group',
  parameters: {
    neptune_query_timeout: '120000',
  },
});

const cluster = new neptune.DatabaseCluster(this, 'Database', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  clusterParameterGroup: clusterParams,
  parameterGroup: dbParams,
});
```

注:使用海王星引擎版本 `1.2.0.0` 或以后,包括新增加的 `1.4` 序列,需要指定合适的 `engineVersion` 道具输入 `neptune.DatabaseCluster`此外,在1.2、1.3和1.4系列中,相应的 `family` 道具必须设置为 `ParameterGroupFamily.NEPTUNE_1_2`, (中文(简体) ), `ParameterGroupFamily.NEPTUNE_1_3` 或者说 `ParameterGroupFamily.NEPTUNE_1_4` 分别为 `neptune.ClusterParameterGroup` 财务报告和审定财务报表 `neptune.ParameterGroup`。 。 。 .

## 添加复制品

`DatabaseCluster` 允许与作者实例一起发射复制件。 可用 `instanceCount` 属性.

```ts
const cluster = new neptune.DatabaseCluster(this, 'Database', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  instances: 2,
});
```

此外,还有可能使用 `DatabaseInstance` 用于一个已存在的集群.

```ts
const replica1 = new neptune.DatabaseInstance(this, 'Instance', {
  cluster,
  instanceType: neptune.InstanceType.R5_LARGE,
});
```

## 自动小版本升级

通过设置 `autoMinorVersionUpgrade` 到真, 海王星会自动更新 将整个集群的引擎稳定到最近一个小版本 窗口2至3周.

```ts
new neptune.DatabaseCluster(this, 'Cluster', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  autoMinorVersionUpgrade: true,
});
```

您也可以指定 `autoMinorVersionUpgrade` 到数据库实例. 即使在同一组内,也可以修改 `autoMinorVersionUpgrade` 设置为逐项设置.

```ts
new neptune.DatabaseInstance(this, 'Instance', {
  cluster,
  instanceType: neptune.InstanceType.R5_LARGE,
  autoMinorVersionUpgrade: true,
});
```

## 端口

默认情况下, 海王星使用端口 `8182`。您可以通过指定 `port` 属性 :

```ts
const cluster = new neptune.DatabaseCluster(this, 'Database', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  port: 12345,
});
```

## 日志

海王星支持各种监测性能和使用的方法. 其中一个方法就是伐木

1.  海王星提供日志,例如审计日志可通过AWS控制台查看或下载。 审计日志可以使用 `neptune_enable_audit_log` 参数在 `ClusterParameterGroup` 或者说 `ParameterGroup`
2.  海王星提供了将这些日志导出到 Cloud Watch 日志的能力

```ts
// Cluster parameter group with the neptune_enable_audit_log param set to 1
const clusterParameterGroup = new neptune.ClusterParameterGroup(this, 'ClusterParams', {
  description: 'Cluster parameter group',
  parameters: {
    neptune_enable_audit_log: '1'
  },
});

const cluster = new neptune.DatabaseCluster(this, 'Database', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  // Audit logs are enabled via the clusterParameterGroup
  clusterParameterGroup,
  // Optionally configuring audit logs to be exported to CloudWatch Logs
  cloudwatchLogsExports: [neptune.LogType.AUDIT],
  // Optionally set a retention period on exported CloudWatch Logs
  cloudwatchLogsRetention: logs.RetentionDays.ONE_MONTH,
});
```

有关监测的更多信息,参见: [https://docs.aws.amazon.com/neptune/latest/userguide/monitory.html 页面存档备份,存于互联网档案馆](https://docs.aws.amazon.com/neptune/latest/userguide/monitoring.html)。 。 。 . 有关审计日志的更多信息,参见 [https://docs.aws.amazon.com/neptune/latest/userguide/auditing.html 页面存档备份,存于互联网档案馆](https://docs.aws.amazon.com/neptune/latest/userguide/auditing.html)。 。 。 . 关于将日志导出至云表日志的更多信息,请参见: [https://docs.aws.amazon.com/neptune/latest/userguide/cloudwatch-logs.html 页面存档备份,存于互联网档案馆](https://docs.aws.amazon.com/neptune/latest/userguide/cloudwatch-logs.html)。 。 。 .

## 计量

两者 `DatabaseCluster` 财务报告和审定财务报表 `DatabaseInstance` 提供 `metric()` 有助于集群一级和实例一级监测的方法.

```ts
declare const cluster: neptune.DatabaseCluster;
declare const instance: neptune.DatabaseInstance;

cluster.metric('SparqlRequestsPerSec'); // cluster-level SparqlErrors metric
instance.metric('SparqlRequestsPerSec') // instance-level SparqlErrors metric
```

关于现有衡量标准的更详细情况,请参见: [https://docs.aws.amazon.com/neptune/latest/userguide/cw-meters.html 互联网档案馆的存檔,存档日期2013-12-22](https://docs.aws.amazon.com/neptune/latest/userguide/cw-metrics.html)

## 复制标记到快照

通过设置 `copyTagsToSnapshot` 中,集群的所有标记在创建时都会被复制到快照中.

```ts
const cluster = new neptune.DatabaseCluster(this, 'Database', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  copyTagsToSnapshot: true  // whether to save the cluster tags when creating the snapshot.
});
```

## 无海王星服务器

您可以使用指定实例类型和 `serverlessScalingConfiguration` 属性.

> 访问 [使用 Amazon Neptune 服务器](https://docs.aws.amazon.com/neptune/latest/userguide/neptune-serverless-using.html) 更多细节.

```ts
const cluster = new neptune.DatabaseCluster(this, 'ServerlessDatabase', {
  vpc,
  instanceType: neptune.InstanceType.SERVERLESS,
  serverlessScalingConfiguration: {
    minCapacity: 1,
    maxCapacity: 5,
  },
});
```

## 常见问题

### @aws-cdk/aws-neptune-alpha 是什么？

AWS: Neptune 的 CDK 构造库

### 如何安装 @aws-cdk/aws-neptune-alpha？

在项目目录运行 npm install @aws-cdk/aws-neptune-alpha，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：constructs（^10\.5\.0）、aws-cdk-lib（^2\.275\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @aws-cdk/aws-neptune-alpha 支持 TypeScript 吗？

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

### @aws-cdk/aws-neptune-alpha 支持 ESM 还是 CommonJS？

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

### @aws-cdk/aws-neptune-alpha 需要什么版本的 Node\.js？

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

### @aws-cdk/aws-neptune-alpha 可以商用吗？

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

### @aws-cdk/aws-neptune-alpha 的下载量有多少？

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

### @aws-cdk/aws-neptune-alpha 还在维护吗？

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

