

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

# 使用 IAM 政策控制對資料目錄的存取
<a name="datacatalogs-iam-policy"></a>

若要控制對資料目錄的存取，請使用資源層級 IAM 許可或身分型 IAM 政策。

下列程序專用於 Athena。

如需 IAM 特定的資訊，請參閱本節最後列出的連結。如需範例 JSON 資料目錄政策的相關資訊，請參閱[資料目錄範例政策](datacatalogs-example-policies.md)。

**若要在 IAM 主控台中使用視覺化編輯器來建立資料目錄政策**

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在左邊的導覽窗格中，選擇 **Policies** (政策)，然後選擇 **Create policy** (建立政策)。

1. 在 **Visual editor** (視覺化編輯器) 標籤上，選擇 **Choose a service** (選擇一項服務)。接著選擇 Athena 以新增到政策。

1. 選擇 **Select actions** (選取動作)，然後選擇要新增到政策的動作。視覺化編輯器會顯示 Athena 中可用的動作。如需詳細資訊，請參閱《服務授權參考》**中的 [Amazon Athena 的動作、資源和條件索引鍵](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html)。

1. 選擇 **add actions** (新增動作) 來輸入特定動作，或使用萬用字元 (\$1) 來指定多個動作。

   預設情況下，您建立的政策允許執行選擇的操作。對於 Athena 中的 `datacatalog` 資源，如果您選擇的一個或多個動作支援資源層級許可，則編輯器會列出 `datacatalog` 資源。

1. 選擇 **Resources (資源)** 來為您的政策指定資料目錄。如需 JSON 資料目錄政策範例，請參閱[資料目錄範例政策](datacatalogs-example-policies.md)。

1. 如下所示指定 `datacatalog` 資源：

   ```
   arn:aws:athena:<region>:<user-account>:datacatalog/<datacatalog-name>
   ```

1. 選擇 **Review policy** (檢閱政策)，然後為您正在建立的政策輸入 **Name** (名稱) 與 **Description** (描述) (選用)。檢閱政策摘要來確認您已授予想要的許可。

1. 選擇 **Create policy** (建立政策) 儲存您的新政策。

1. 將此以身分為基礎的政策連接到使用者、群組或角色，並指定其可存取的 `datacatalog` 資源。

如需詳細資訊，請參閱《服務授權參考》**與《IAM 使用者指南》**中的下列主題：
+ [Amazon Athena 的操作、資料和條件索引鍵](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html)
+ [使用視覺化編輯器來建立政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-visual-editor)
+ [新增和移除 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)
+ [控制資源的存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_controlling.html#access_controlling-resources)

如需 JSON 資料目錄政策範例，請參閱[資料目錄範例政策](datacatalogs-example-policies.md)。

如需 AWS Glue 許可和 AWS Glue 爬蟲程式許可的相關資訊，請參閱《 *AWS Glue 開發人員指南*》中的[設定 和爬蟲程式先決條件的 IAM 許可 AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/getting-started-access.html)。 [https://docs.aws.amazon.com/glue/latest/dg/crawler-prereqs.html](https://docs.aws.amazon.com/glue/latest/dg/crawler-prereqs.html)

如需 Amazon Athena 動作的完整清單，請參閱《[Amazon Athena API 參考](https://docs.aws.amazon.com/athena/latest/APIReference/)》中的 API 動作名稱。

# 資料目錄範例政策
<a name="datacatalogs-example-policies"></a>

本節包含可讓您在資料目錄上用來啟用各種動作的政策範例。

資料目錄是由 Athena 管理的 IAM 資源。因此，如果您的資料目錄政策使用 `datacatalog` 做為輸入的動作，您必須指定資料目錄的 ARN，如下所示：

```
"Resource": [arn:aws:athena:<region>:<user-account>:datacatalog/<datacatalog-name>]
```

`<datacatalog-name>` 是資料目錄的名稱。例如，對於名為 `test_datacatalog` 的資料目錄，將其指定為資源，如下所示：

```
"Resource": ["arn:aws:athena:us-east-1:123456789012:datacatalog/test_datacatalog"]
```

如需 Amazon Athena 動作的完整清單，請參閱《[Amazon Athena API 參考](https://docs.aws.amazon.com/athena/latest/APIReference/)》中的 API 動作名稱。如需有關 IAM 政策的詳細資訊，請參閱《IAM 使用者指南》**中的[使用視覺化編輯器來建立政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-visual-editor)。如需有關為工作群組建立 IAM 政策的詳細資訊，請參閱[使用 IAM 政策控制對資料目錄的存取](datacatalogs-iam-policy.md)。
+ [Example Policy for Full Access to All Data Catalogs](#datacatalog-policy-full-access-to-all-data-catalogs)
+ [Example Policy for Full Access to a Specified Data Catalog](#datacatalog-policy-full-access-to-a-specified-catalog)
+ [Example Policy for Querying a Specified Data Catalog](#datacatalog-policy-querying-a-specified-data-catalog)
+ [Example Policy for Management Operations on a Specified Data Catalog](#datacatalog-policy-management-operations-on-a-specified-catalog)
+ [Example Policy for Listing Data Catalogs](#datacatalog-policy-listing-data-catalogs)
+ [Example Policy for Metadata Operations on Data Catalogs](#datacatalog-policy-metadata-operations)

**Example 適用於完整存取所有資料目錄的政策範例**  
以下政策允許完整存取帳戶中可能存在的所有資料目錄資源。對於您的帳戶中必須為所有其他使用者管理資料目錄的那些使用者，我們建議您使用此政策。    
****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "athena:*"
         ],
         "Resource":[
            "*"
         ]
      }
   ]
}
```

**Example 適用於完整存取指定資料目錄的政策範例**  
以下政策允許完整存取名為 `datacatalogA` 的單一特定的資料目錄資源。對於能夠完全控制特定資料目錄的使用者，您可以使用此政策。    
****  

```
{ "Version":"2012-10-17",		 	 	  "Statement":[ { "Effect":"Allow", "Action":[
   "athena:ListDataCatalogs", "athena:ListWorkGroups", "athena:GetDatabase", "athena:ListDatabases",
   "athena:ListTableMetadata", "athena:GetTableMetadata" ], "Resource":"*" }, { "Effect":"Allow",
   "Action":[ "athena:StartQueryExecution", "athena:GetQueryResults", "athena:DeleteNamedQuery",
   "athena:GetNamedQuery", "athena:ListQueryExecutions", "athena:StopQueryExecution",
   "athena:GetQueryResultsStream", "athena:ListNamedQueries", "athena:CreateNamedQuery",
   "athena:GetQueryExecution", "athena:BatchGetNamedQuery", "athena:BatchGetQueryExecution",
   "athena:DeleteWorkGroup", "athena:UpdateWorkGroup", "athena:GetWorkGroup",
   "athena:CreateWorkGroup" ], "Resource":[
      "arn:aws:athena:us-east-1:123456789012:workgroup/*"
   ] }, { "Effect":"Allow", "Action":[ "athena:CreateDataCatalog", "athena:DeleteDataCatalog",
   "athena:GetDataCatalog", "athena:GetDatabase", "athena:GetTableMetadata", "athena:ListDatabases",
   "athena:ListTableMetadata", "athena:UpdateDataCatalog" ],
      "Resource":"arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA"
   } ] }
```

**Example 適用於查詢指定資料目錄的政策範例**  
在以下政策中，允許使用者在指定的 `datacatalogA` 中執行查詢。不允許使用者對資料目錄本身執行管理任務，例如更新或刪除。    
****  

```
{ "Version":"2012-10-17",		 	 	  "Statement":[ { "Effect":"Allow", "Action":[
   "athena:StartQueryExecution" ], "Resource":[
      "arn:aws:athena:us-east-1:123456789012:workgroup/*"
   ] }, { "Effect":"Allow", "Action":[ "athena:GetDataCatalog" ], "Resource":[
      "arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA"
   ] } ] }
```

**Example 適用於指定資料目錄上管理操作的政策範例**  
在以下政策中，允許使用者建立、刪除、取得詳細資訊和更新資料目錄 `datacatalogA`。    
****  

```
{ "Version":"2012-10-17",		 	 	  "Statement": [ { "Effect": "Allow", "Action": [
    "athena:CreateDataCatalog", "athena:GetDataCatalog", "athena:DeleteDataCatalog",
    "athena:UpdateDataCatalog" ], "Resource": [
        "arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA"
    ] } ] }
```

**Example 適用於列出資料目錄的政策範例**  
以下政策可讓所有使用者列出所有資料目錄：    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "athena:ListDataCatalogs"
            ],
            "Resource": "*"
        }
    ]
}
```

**Example 適用於資料目錄上中繼資料操作的政策範例**  
下列政策允許對資料目錄進行中繼資料操作：    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "athena:GetDatabase",
                "athena:GetTableMetadata",
                "athena:ListDatabases",
                "athena:ListTableMetadata"
            ],
            "Resource": "*"
        }
    ]
}
```