亚马逊海王星构造库
本单元中更高层次的构件的API是实验性的并正在积极开发中. 在今后任何版本中,它们都须作非背向相容的修改或去除。 这些是 不适用 语义版本 模型和断开的更改 在发行笔记中宣布. 这意味着虽然你可能使用它们,但可能需要更新 当更新到此软件包的更新版本时,您的源代码.
亚马逊 Neptune是一个快速,可靠,完全管理的图数据库服务,它使得与高度连接的数据集一起工作的应用程序易于构建和运行. 海王星的核心是一个目的建造的高性能图数据库引擎. 此引擎被优化,用于存储数十亿个关系,并用毫秒的耐用来查询图. Neptune支持流行的图查询语言Apache TinkerPop Gremlin和W3C的SPARQL,使您能够构建能高效地导航高连接数据集的查询.
这个 @aws-cdk/aws-neptune-alpha 软件包包含用于建立海王星数据库集群和实例的原始数据.
import * as neptune from '@aws-cdk/aws-neptune-alpha';
启动海王星数据库
为了建立海王星数据库,定义 DatabaseCluster您必须在 VPC 中启动数据库 .
const cluster = new neptune.DatabaseCluster(this, 'Database', {
vpc,
instanceType: neptune.InstanceType.R5_LARGE,
});
默认情况下, 只能提供写家实例 .
连接中
要控制谁可以访问集群,请使用 .connections 属性。 海王星数据库有一个默认的端口,所以
您不需要指定端口 :
cluster.connections.allowDefaultPortFromAnyIpv4('Open to the world');
访问您数据库集群的终点将作为 .clusterEndpoint 财务报告和审定财务报表 .clusterReadEndpoint
属性 :
const writeAddress = cluster.clusterEndpoint.socketAddress; // "HOSTNAME:PORT"
IAM 认证
也可以使用 AWS 身份和访问管理(IAM) 数据库认证认证到数据库集群; 见 https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth.html 互联网档案馆的存檔,存档日期2013-12-22 需要更多信息和所支持的列表 版本和限制.
以下例子显示可以对数据库集群进行IAM认证,并允许连接访问IAM角色.
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 页面存档备份,存于互联网档案馆
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
属性.
const cluster = new neptune.DatabaseCluster(this, 'Database', {
vpc,
instanceType: neptune.InstanceType.R5_LARGE,
instances: 2,
});
此外,还有可能使用 DatabaseInstance 用于一个已存在的集群.
const replica1 = new neptune.DatabaseInstance(this, 'Instance', {
cluster,
instanceType: neptune.InstanceType.R5_LARGE,
});
自动小版本升级
通过设置 autoMinorVersionUpgrade 到真, 海王星会自动更新
将整个集群的引擎稳定到最近一个小版本
窗口2至3周.
new neptune.DatabaseCluster(this, 'Cluster', {
vpc,
instanceType: neptune.InstanceType.R5_LARGE,
autoMinorVersionUpgrade: true,
});
您也可以指定 autoMinorVersionUpgrade 到数据库实例.
即使在同一组内,也可以修改 autoMinorVersionUpgrade 设置为逐项设置.
new neptune.DatabaseInstance(this, 'Instance', {
cluster,
instanceType: neptune.InstanceType.R5_LARGE,
autoMinorVersionUpgrade: true,
});
端口
默认情况下, 海王星使用端口 8182。您可以通过指定 port 属性 :
const cluster = new neptune.DatabaseCluster(this, 'Database', {
vpc,
instanceType: neptune.InstanceType.R5_LARGE,
port: 12345,
});
日志
海王星支持各种监测性能和使用的方法. 其中一个方法就是伐木
- 海王星提供日志,例如审计日志可通过AWS控制台查看或下载。 审计日志可以使用
neptune_enable_audit_log参数在ClusterParameterGroup或者说ParameterGroup - 海王星提供了将这些日志导出到 Cloud Watch 日志的能力
// 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/auditing.html 页面存档备份,存于互联网档案馆。 。 。 . 关于将日志导出至云表日志的更多信息,请参见: https://docs.aws.amazon.com/neptune/latest/userguide/cloudwatch-logs.html 页面存档备份,存于互联网档案馆。 。 。 .
计量
两者 DatabaseCluster 财务报告和审定财务报表 DatabaseInstance 提供 metric() 有助于集群一级和实例一级监测的方法.
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
复制标记到快照
通过设置 copyTagsToSnapshot 中,集群的所有标记在创建时都会被复制到快照中.
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 服务器 更多细节.
const cluster = new neptune.DatabaseCluster(this, 'ServerlessDatabase', {
vpc,
instanceType: neptune.InstanceType.SERVERLESS,
serverlessScalingConfiguration: {
minCapacity: 1,
maxCapacity: 5,
},
});