

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建自定义 IAM 策略语句来访问 Amazon Neptune 中的数据
<a name="iam-data-access-policies"></a>

Neptune 数据访问策略语句使用[数据访问操作](iam-dp-actions.md)、[资源](iam-data-resources.md)和[条件键](iam-data-condition-keys.md#iam-neptune-condition-keys)，所有这些都以 `neptune-db:` 前缀开头。

**Topics**
+ [在 Neptune 数据访问策略语句中使用查询操作](#iam-data-query-actions)
+ [用于在 Amazon Neptune 中访问数据的 IAM 操作](iam-dp-actions.md)
+ [用于在 Amazon Neptune 中访问数据的 IAM 资源类型](iam-data-resources.md)
+ [用于在 Amazon Neptune 中访问数据的 IAM 条件键](iam-data-condition-keys.md)
+ [在 Amazon Neptune 中创建 IAM 数据访问策略](iam-data-access-examples.md)

## 在 Neptune 数据访问策略语句中使用查询操作
<a name="iam-data-query-actions"></a>

在数据访问策略语句中可以使用三个 Neptune 查询操作，即 `ReadDataViaQuery`、`WriteDataViaQuery` 和 `DeleteDataViaQuery`。特定的查询可能需要权限才能执行其中多个操作，而且可能并不总是很清楚必须允许这些操作的哪种组合才能运行查询。

在运行查询之前，Neptune 会确定运行每个查询步骤所需的权限，并将这些权限组合成查询所需的完整权限集。请注意，这组完整的权限包括查询*可能*执行的所有操作，这些操作不一定是查询在数据上运行时实际执行的一组操作。

这意味着，要允许给定的查询运行，必须针对该查询可能执行的每个操作提供权限，无论它是否实际执行这些操作。

以下是一些示例 Gremlin 查询，其中对此进行了更详细的解释：
+ 

  ```
  g.V().count()
  ```

  `g.V()` 和 `count()` 只需要读取权限，因此整个查询只需要 `ReadDataViaQuery` 访问权限。
+ 

  ```
  g.addV()
  ```

  在插入新顶点之前，`addV()` 需要检查具有给定 ID 的顶点是否存在。这意味着它同时需要 `ReadDataViaQuery` 和 `WriteDataViaQuery` 访问权限。
+ 

  ```
  g.V('1').as('a').out('created').addE('createdBy').to('a')
  ```

  `g.V('1').as('a')` 和 `out('created')` 只需要读取权限，但 `addE().from('a')` 同时需要读取和写入权限，因为在添加新边缘之前，`addE()` 需要读取 `from` 和 `to` 顶点并检查是否已经存在具有相同 ID 的边缘。因此，整个查询同时需要 `ReadDataViaQuery` 和 `WriteDataViaQuery` 访问权限。
+ 

  ```
  g.V().drop()
  ```

  `g.V()` 只需要读取访问权限。`drop()` 同时需要读取和删除访问权限，因为它需要在删除顶点或边缘之前读取顶点或边缘，因此查询总体同时需要 `ReadDataViaQuery` 和 `DeleteDataViaQuery` 访问权限。
+ 

  ```
  g.V('1').property(single, 'key1', 'value1')
  ```

  `g.V('1')` 只需要读取访问权限，但 `property(single, 'key1', 'value1')` 需要读取、写入和删除访问权限。在这里，如果键和值尚不存在于顶点中，则 `property()` 步骤会插入它们，但如果它们已经存在，则该步骤会删除现有的属性值并在其位置插入一个新值。因此，整个查询需要 `ReadDataViaQuery`、`WriteDataViaQuery` 和 `DeleteDataViaQuery` 访问权限。

  任何包含 `property()` 步骤的查询都需要 `ReadDataViaQuery`、`WriteDataViaQuery` 和 `DeleteDataViaQuery` 权限。

下面是一些 openCypher 示例：
+ 

  ```
  MATCH (n)
  RETURN n
  ```

  此查询读取数据库中的所有节点并返回它们，这只需要 `ReadDataViaQuery` 访问权限即可。
+ 

  ```
  MATCH (n:Person)
  SET n.dept = 'AWS'
  ```

  此查询需要 `ReadDataViaQuery`、`WriteDataViaQuery` 和 `DeleteDataViaQuery` 访问权限。它会读取所有标签为“Person”的节点，然后向它们添加一个带有键 `dept` 和值 `AWS` 的新属性，或者如果该 `dept` 属性已经存在，则删除旧值并改为插入 `AWS`。此外，如果要设置的值为 `null`，`SET` 会完全删除该属性。

   由于 `SET` 子句在某些情况下可能需要删除现有值，因此它**始终**需要 `DeleteDataViaQuery` 权限以及 `ReadDataViaQuery` 和 `WriteDataViaQuery` 权限。
+ 

  ```
  MATCH (n:Person)
  DETACH DELETE n
  ```

  此查询需要 `ReadDataViaQuery` 和 `DeleteDataViaQuery` 权限。它会找到所有带有标签 `Person` 的节点，并将它们以及连接到这些节点的边缘和任何关联的标签和属性一起删除。
+ 

  ```
  MERGE (n:Person {name: 'John'})-[:knows]->(:Person {name: 'Peter'})
  RETURN n
  ```

  此查询需要 `ReadDataViaQuery` 和 `WriteDataViaQuery` 权限。`MERGE` 子句要么匹配指定的模式，要么创建该模式。因为当模式不匹配时，可能会发生写入操作，因此需要写入权限以及读取权限。

# 用于在 Amazon Neptune 中访问数据的 IAM 操作
<a name="iam-dp-actions"></a>

请注意，Neptune 数据访问操作具有前缀 `neptune-db:`，而 Neptune 中的管理操作具有前缀 `rds:`。

IAM 中的数据资源的 Amazon 资源名称 (ARN) 与创建时分配给集群的 ARN 不同。您必须按照[指定数据资源](iam-data-resources.md)中所示构造 ARN。此类数据资源 ARNs可以使用通配符来包含多个资源。

数据访问策略声明还可以包含 ne [ptune-db: QueryLanguage](iam-data-condition-keys.md#iam-neptune-condition-keys) 条件键，以限制按查询语言进行访问。

从[版本：1.2.0.0（2022 年 7 月 21 日）](engine-releases-1.2.0.0.md) 开始，Neptune 支持将权限限制为一个或多个[特定的 Neptune 操作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonneptune.html)。这提供了比以前更精细的访问控制。

**重要**  
对 IAM policy 的更改将需要长达 10 分钟才能应用于指定的 Neptune 资源。
应用于 Neptune 数据库集群的 IAM policy 将应用于集群中的所有实例。

## *基于查询的数据访问操作*
<a name="iam-dp-actions-queries"></a>

**注意**  
运行给定查询需要什么权限并不总是显而易见的，因为根据查询处理的数据，查询可能会采取多个操作。请参阅[使用查询操作](iam-data-access-policies.md#iam-data-query-actions)了解更多信息。

## `neptune-db:ReadDataViaQuery`
<a name="readdataviaquery"></a>

`ReadDataViaQuery` 允许用户通过提交查询从 Neptune 数据库中读取数据。

*操作组：*只读、读写。

*操作上下文键*：`neptune-db:QueryLanguage`。

*所需资源*：数据库。

## `neptune-db:WriteDataViaQuery`
<a name="writedataviaquery"></a>

`WriteDataViaQuery` 允许用户通过提交查询将数据写入 Neptune 数据库。

*操作组*：读写。

*操作上下文键*：`neptune-db:QueryLanguage`。

*所需资源*：数据库。

## `neptune-db:DeleteDataViaQuery`
<a name="deletedataviaquery"></a>

`DeleteDataViaQuery` 允许用户通过提交查询从 Neptune 数据库中删除数据。

*操作组*：读写。

*操作上下文键*：`neptune-db:QueryLanguage`。

*所需资源*：数据库。

## `neptune-db:GetQueryStatus`
<a name="getquerystatus"></a>

`GetQueryStatus` 允许用户检查所有活动查询的状态。

*操作组：*只读、读写。

*操作上下文键*：`neptune-db:QueryLanguage`。

*所需资源*：数据库。

## `neptune-db:GetStreamRecords`
<a name="getstreamrecords"></a>

`GetStreamRecords` 允许用户从 Neptune 提取流记录。

*操作组*：读写。

*操作上下文键*：`neptune-db:QueryLanguage`。

*所需资源*：数据库。

## `neptune-db:CancelQuery`
<a name="cancelquery"></a>

`CancelQuery` 允许用户取消查询。

*操作组*：读写。

*所需资源*：数据库。

## *常规数据访问操作*
<a name="iam-dp-actions-general"></a>

## `neptune-db:GetEngineStatus`
<a name="getenginestatus"></a>

`GetEngineStatus` 允许用户检查 Neptune 引擎的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:GetStatisticsStatus`
<a name="getstatisticsstatus"></a>

`GetStatisticsStatus` 允许用户检查为数据库收集的统计数据的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:GetGraphSummary`
<a name="getgraphsummary"></a>

`GetGraphSummary` 图形摘要 API 允许您检索图形的只读摘要。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:ManageStatistics`
<a name="managestatistics"></a>

`ManageStatistics` 允许用户管理数据库的统计数据收集。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:DeleteStatistics`
<a name="deletestatistics"></a>

`DeleteStatistics` 允许用户删除数据库中的所有统计数据。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:ResetDatabase`
<a name="resetdatabase"></a>

`ResetDatabase` 允许用户获取重置所需的令牌，并重置 Neptune 数据库。

*操作组*：读写。

*所需资源*：数据库。

## *批量加载程序数据访问操作*
<a name="iam-dp-actions-loader"></a>

## `neptune-db:StartLoaderJob`
<a name="startloaderjob"></a>

`StartLoaderJob` 允许用户启动批量加载程序任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:GetLoaderJobStatus`
<a name="getloaderjobstatus"></a>

`GetLoaderJobStatus` 允许用户检查批量加载程序任务的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:ListLoaderJobs`
<a name="listloaderjobs"></a>

`ListLoaderJobs` 允许用户列出所有批量加载程序任务。

*操作组*：仅列出、只读、读写。

*所需资源*：数据库。

## `neptune-db:CancelLoaderJob`
<a name="cancelloaderjob"></a>

`CancelLoaderJob` 允许用户取消加载程序任务。

*操作组*：读写。

*所需资源*：数据库。

## *机器学习数据访问操作*
<a name="iam-dp-actions-ml"></a>

## `neptune-db:StartMLDataProcessingJob`
<a name="startmldataprocessingjob"></a>

`StartMLDataProcessingJob` 允许用户启动 Neptune ML 数据处理任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:StartMLModelTrainingJob`
<a name="startmlmodeltrainingjob"></a>

`StartMLModelTrainingJob` 允许用户启动 ML 模型训练任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:StartMLModelTransformJob`
<a name="startmlmodeltransformjob"></a>

`StartMLModelTransformJob` 允许用户启动 ML 模型转换任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:CreateMLEndpoint`
<a name="createmlendpoint"></a>

`CreateMLEndpoint` 允许用户创建 Neptune 机器学习端点。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:GetMLDataProcessingJobStatus`
<a name="getmldataprocessingjobstatus"></a>

`GetMLDataProcessingJobStatus` 允许用户检查 Neptune ML 数据处理任务的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:GetMLModelTrainingJobStatus`
<a name="getmlmodeltrainingjobstatus"></a>

`GetMLModelTrainingJobStatus` 允许用户检查 Neptune ML 模型训练任务的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:GetMLModelTransformJobStatus`
<a name="getmlmodeltransformjobstatus"></a>

`GetMLModelTransformJobStatus` 允许用户检查 Neptune ML 模型转换任务的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:GetMLEndpointStatus`
<a name="getmlendpointstatus"></a>

`GetMLEndpointStatus` 允许用户检查 Neptune ML 端点的状态。

*操作组：*只读、读写。

*所需资源*：数据库。

## `neptune-db:ListMLDataProcessingJobs`
<a name="listmldataprocessingjobs"></a>

`ListMLDataProcessingJobs` 允许用户列出所有 Neptune ML 数据处理任务。

*操作组*：仅列出、只读、读写。

*所需资源*：数据库。

## `neptune-db:ListMLModelTrainingJobs`
<a name="listmlmodeltrainingjobs"></a>

`ListMLModelTrainingJobs` 允许用户列出所有 Neptune ML 模型训练任务。

*操作组*：仅列出、只读、读写。

*所需资源*：数据库。

## `neptune-db:ListMLModelTransformJobs`
<a name="listmlmodeltransformjobs"></a>

`ListMLModelTransformJobs` 允许用户列出所有 ML 模型转换任务。

*操作组*：仅列出、只读、读写。

*所需资源*：数据库。

## `neptune-db:ListMLEndpoints`
<a name="listmlendpoints"></a>

`ListMLEndpoints` 允许用户列出所有 Neptune ML 端点。

*操作组*：仅列出、只读、读写。

*所需资源*：数据库。

## `neptune-db:CancelMLDataProcessingJob`
<a name="cancelmldataprocessingjob"></a>

`CancelMLDataProcessingJob` 允许用户取消 Neptune ML 数据处理任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:CancelMLModelTrainingJob`
<a name="cancelmlmodeltrainingjob"></a>

`CancelMLModelTrainingJob` 允许用户取消 Neptune ML 模型训练任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:CancelMLModelTransformJob`
<a name="cancelmlmodeltransformjob"></a>

`CancelMLModelTransformJob` 允许用户取消 Neptune ML 模型转换任务。

*操作组*：读写。

*所需资源*：数据库。

## `neptune-db:DeleteMLEndpoint`
<a name="deletemlendpoint"></a>

`DeleteMLEndpoint` 允许用户删除 Neptune 机器学习端点。

*操作组*：读写。

*所需资源*：数据库。

# 用于在 Amazon Neptune 中访问数据的 IAM 资源类型
<a name="iam-data-resources"></a>

数据资源（如数据操作）具有 `neptune-db:` 前缀。

在 Neptune 数据访问策略中，您可以按以下格式在 ARN 中指定要授予访问权限的数据库集群：

```
arn:aws:neptune-db:region:account-id:cluster-resource-id/*
```

这样的资源 ARN 包含以下部分：
+ `region`是 Amazon Neptune 数据库集群的 AWS 区域。
+ `account-id` 是数据库集群的 AWS 账号。
+ `cluster-resource-id` 是数据库集群的资源 ID。
**重要**  
`cluster-resource-id` 不同于集群标识符。要在 Neptune 中查找群集资源 ID AWS 管理控制台，请在 “**配置**” 部分中查找相关数据库集群。

# 用于在 Amazon Neptune 中访问数据的 IAM 条件键
<a name="iam-data-condition-keys"></a>

[使用条件键](security-iam-access-manage.md#iam-using-condition-keys)，您可以在 IAM policy 语句中指定条件，这样该语句仅在条件为 true 时才生效。

您可以在 Neptune 数据访问策略语句中使用的条件键分为以下几类：
+ [全局条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html) [-下面列出了 Neptune 在数据访问策略声明中支持的 AWS 全局条件键的子集。](#iam-data-global-condition-keys)
+ [特定于服务的条件键](#iam-neptune-condition-keys) – 这些键由 Neptune 定义，专门用于数据访问策略语句中。目前只有一个 ne [ptune-db: QueryLanguage](#neptune-db-query-language)，它只有在使用特定的查询语言时才授予访问权限。

## AWS Neptune 在数据访问策略声明中支持的全局条件上下文密钥
<a name="iam-data-global-condition-keys"></a>

下表列出了 Amazon Neptune 支持在数据访问策略语句中使用的 [AWS 全局条件上下文键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)的子集：


**可在数据访问策略语句中使用的全局条件键**  

| 条件键 | 描述 | Type | 
| --- | --- | --- | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-currenttime](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-currenttime) | 按请求的当前日期和时间筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-epochtime](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-epochtime) | 按请求的日期和时间（以 UNIX 纪元值表示）筛选访问。 | Numeric | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalaccount](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalaccount) | 按发出请求的主体所属的账户筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalarn](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalarn) | 按发出请求的主体的 ARN 筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalisawsservice](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalisawsservice) | 仅当呼叫由 AWS 服务主体直接拨打时才允许访问。 | Boolean | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalorgid](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalorgid) | 根据请求委托人所属的 Organizations 中的 AWS 组织标识符筛选访问权限。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalorgpaths](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalorgpaths) | 按 AWS Organizations 路径筛选提出请求的委托人的访问权限。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principaltag](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principaltag) | 按附加到发出请求的主体的标签筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principaltype](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principaltype) | 按发出请求的主体的类型筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-requestedregion](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-requestedregion) | 按请求中调用的 AWS 区域筛选访问权限。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-securetransport](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-securetransport) | 仅当使用 SSL 发送请求时才允许访问。 | Boolean | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceip](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceip) | 按请求者的 IP 地址筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-tokenissuetime](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-tokenissuetime) | 按颁发临时安全凭证的日期和时间筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-useragent](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-useragent) | 按请求者的客户端应用程序筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-userid](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-userid) | 按请求者的主体标识符筛选访问。 | String | 
| [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-viaawsservice](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-viaawsservice) | 仅当 AWS 服务代表您提出请求时才允许访问。 | Boolean | 

## Neptune 特定于服务的条件键
<a name="iam-neptune-condition-keys"></a>

Neptune 针对 IAM policy 支持以下特定于服务的条件键：


**Neptune 特定于服务的条件键**  

| 条件键 | 描述 | Type | 
| --- | --- | --- | 
| neptune-db:QueryLanguage |  按所使用的查询语言筛选数据访问权限。 有效值包括 `Gremlin`、`OpenCypher` 和 `Sparql`。 支持的操作为 `ReadDataViaQuery`、`WriteDataViaQuery`、`DeleteDataViaQuery`、`GetQueryStatus` 和 `CancelQuery`。  | String | 

# 在 Amazon Neptune 中创建 IAM 数据访问策略
<a name="iam-data-access-examples"></a>

[以下示例展示了如何创建自定义 IAM 策略，这些策略使用 Neptune 引擎发行版 1.2.0.0 中引入的数据平面 APIs 和操作的精细访问控制。](engine-releases-1.2.0.0.md)

## 策略示例：允许不受限制地访问 Neptune 数据库集群中的数据
<a name="iam-auth-data-policy-example-general"></a>

以下示例策略允许 IAM 用户使用 IAM 数据库身份验证连接到 Neptune 数据库集群，并使用“`*`”字符匹配所有可用的操作。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "neptune-db:*",
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

以上示例包含采用特定于 Neptune IAM 身份验证的格式的资源 ARN。要构造 ARN，请参阅[指定数据资源](iam-data-resources.md)。请注意，用于 IAM 授权 `Resource` 的 ARN 与创建时分配给集群的 ARN 不同。

## 允许对 Neptune 数据库集群进行只读访问的策略示例
<a name="iam-auth-data-policy-example-read-only"></a>

以下策略授予对 Neptune 数据库集群中数据的完全只读访问权限：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:Read*",
        "neptune-db:Get*",
        "neptune-db:List*"
      ],
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

## 策略示例：拒绝对 Neptune 数据库集群的所有访问权限
<a name="iam-auth-data-policy-example-deny"></a>

默认 IAM 操作是拒绝对数据库集群的访问，除非授予 `Allow` *效果*。但是，以下策略拒绝特定 AWS 账户和区域对数据库集群的所有访问权限，然后优先于任何`Allow`效果。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Deny",
      "Action": "neptune-db:*",
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

## 策略示例：通过查询授予读取访问权限
<a name="iam-auth-data-policy-example-read-query"></a>

以下策略仅授予使用查询从 Neptune 数据库集群读取数据的权限：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "neptune-db:ReadDataViaQuery",
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

## 仅允许 Gremlin 查询的策略示例
<a name="iam-auth-data-policy-example-gremlin-only"></a>

以下策略使用 `neptune-db:QueryLanguage` 条件键授予仅使用 Gremlin 查询语言查询 Neptune 的权限：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:ReadDataViaQuery",
        "neptune-db:WriteDataViaQuery",
        "neptune-db:DeleteDataViaQuery"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "neptune-db:QueryLanguage": "Gremlin"
        }
      }
    }
  ]
}
```

------

## 策略示例：允许除 Neptune ML 模型管理之外的所有访问权限
<a name="iam-auth-data-policy-example-all-but-ml"></a>

以下策略授予对 Neptune 图形操作的完全访问权限，但 Neptune ML 模型管理特征除外：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:CancelLoaderJob",
        "neptune-db:CancelQuery",
        "neptune-db:DeleteDataViaQuery",
        "neptune-db:DeleteStatistics",
        "neptune-db:GetEngineStatus",
        "neptune-db:GetLoaderJobStatus",
        "neptune-db:GetQueryStatus",
        "neptune-db:GetStatisticsStatus",
        "neptune-db:GetStreamRecords",
        "neptune-db:ListLoaderJobs",
        "neptune-db:ManageStatistics",
        "neptune-db:ReadDataViaQuery",
        "neptune-db:ResetDatabase",
        "neptune-db:StartLoaderJob",
        "neptune-db:WriteDataViaQuery"
      ],
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

## 允许访问 Neptune ML 模型管理的策略示例
<a name="iam-auth-data-policy-example-ml"></a>

此策略授予对 Neptune ML 模型管理特征的访问权限：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:CancelMLDataProcessingJob",
        "neptune-db:CancelMLModelTrainingJob",
        "neptune-db:CancelMLModelTransformJob",
        "neptune-db:CreateMLEndpoint",
        "neptune-db:DeleteMLEndpoint",
        "neptune-db:GetMLDataProcessingJobStatus",
        "neptune-db:GetMLEndpointStatus",
        "neptune-db:GetMLModelTrainingJobStatus",
        "neptune-db:GetMLModelTransformJobStatus",
        "neptune-db:ListMLDataProcessingJobs",
        "neptune-db:ListMLEndpoints",
        "neptune-db:ListMLModelTrainingJobs",
        "neptune-db:ListMLModelTransformJobs",
        "neptune-db:StartMLDataProcessingJob",
        "neptune-db:StartMLModelTrainingJob",
        "neptune-db:StartMLModelTransformJob"
      ],
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

## 策略示例：授予完全查询访问权限
<a name="iam-auth-data-policy-example-full-query"></a>

以下策略授予对 Neptune 图形查询操作的完全访问权限，但不授予对快速重置、流、批量加载程序、Neptune ML 模型管理等特征的完全访问权限：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:ReadDataViaQuery",
        "neptune-db:WriteDataViaQuery",
        "neptune-db:DeleteDataViaQuery",
        "neptune-db:GetEngineStatus",
        "neptune-db:GetQueryStatus",
        "neptune-db:CancelQuery"
      ],
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------

## 策略示例：仅授予对 Gremlin 查询的完全访问权限
<a name="iam-auth-data-policy-example-full-gremlin-access"></a>

以下策略授予使用 Gremlin 查询语言对 Neptune 图形查询操作的完全访问权限，但不授予对其它语言的查询的完全访问权限，也不授予对快速重置、流、批量加载程序、Neptune ML 模型管理等特征的完全访问权限：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:ReadDataViaQuery",
        "neptune-db:WriteDataViaQuery",
        "neptune-db:DeleteDataViaQuery",
        "neptune-db:GetEngineStatus",
        "neptune-db:GetQueryStatus",
        "neptune-db:CancelQuery"
      ],
      "Resource": [
        "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
      ],
      "Condition": {
        "StringEquals": {
           "neptune-db:QueryLanguage":"Gremlin"
        }
      }
    }
  ]
}
```

------

## 策略示例：授予完全访问权限，但快速重置除外
<a name="iam-auth-data-policy-example-all-but-fast-reset"></a>

以下策略授予对 Neptune 数据库集群的完全访问权限，但使用快速重置除外：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "neptune-db:*",
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    },
    {
      "Effect": "Deny",
      "Action": "neptune-db:ResetDatabase",
      "Resource": "arn:aws:neptune-db:us-east-1:123456789012:cluster-ABCD1234EFGH5678IJKL90MNOP/*"
    }
  ]
}
```

------