

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立自訂 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 Resource Name (ARN) 與在建立時指派給叢集的 ARN 不同。您必須建構 ARN，如[指定資料資源](iam-data-resources.md)中所示。這類資料資源 ARN 可以使用萬用字元來包含多個資源。

資料存取政策陳述式也可以包含 [neptune-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)。這提供了可能比以前更精細的存取控制。

**重要**  
最多需要 10 分鐘才能將 IAM 政策的變更套用到指定的 Neptune 資源。
已套用到 Neptune 資料庫叢集的 IAM 政策也會套用到該叢集中的所有執行個體。

## *查詢型資料存取動作*
<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 ML 端點。

*動作群組：*讀寫。

*必要資源：*資料庫。

## `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 ML 端點。

*動作群組：*讀寫。

*必要資源：*資料庫。

# 用於存取 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 政策陳述式中指定條件，以便陳述式只在條件成立時才生效。

您可以在 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 定義的金鑰，專門用於資料存取政策陳述式。目前只有一個，即 [neptune-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 epoch 值表示) 篩選存取。 | 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) | 依請求委託人所屬 AWS 之 Organizations 中組織的識別符篩選存取權。 | 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 政策的下列服務特定條件金鑰：


**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 版](engine-releases-1.2.0.0.md)中引進的資料平面 API 和動作的精細存取控制。

## 允許不受限制地存取 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/*"
    }
  ]
}
```

------

上述範例包含資源 ARN，其格式為 Neptune IAM 身分驗證的專屬格式。若要建構 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/*"
    }
  ]
}
```

------

## 僅對 Gemlin 查詢授與完整存取權的政策範例
<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/*"
    }
  ]
}
```

------