

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

# 設定 Amazon Redshift 資料共用的許可
<a name="setup-ds-perms"></a>

 本主題說明您需要遵循的步驟，以接受資料共用邀請、建立聯合資料庫，以及授予許可。您可以使用 Lake Formation 主控台或 AWS Command Line Interface (AWS CLI)。本主題中的範例顯示相同帳戶中的生產者叢集、資料目錄和資料取用者。

若要進一步了解 Lake Formation 跨帳戶功能，請參閱 [Lake Formation 中的跨帳戶資料共用](cross-account-permissions.md)。

**設定資料共用的許可**

1. 檢閱資料共用邀請並接受它。

------
#### [ Console ]

   1.  以資料湖管理員身分登入 Lake Formation 主控台，網址為 https：//[https://console.aws.amazon.com/lakeformation/](https://console.aws.amazon.com/lakeformation/)。導覽至**資料共用**頁面。

   1. 檢閱您獲授權存取的資料共用。**狀態**欄指出您目前的資料共用參與狀態。**待**定狀態表示您已新增至資料共用，但您尚未接受或拒絕邀請。

   1.  若要回應資料共用邀請，請選取資料共用名稱，然後選擇**檢閱邀請**。在**接受或拒絕資料共用**中，檢閱邀請詳細資訊。選擇**接受**以接受邀請**或拒絕**以拒絕邀請。如果您拒絕邀請，則無法存取資料共用。

------
#### [ AWS CLI ]

   下列範例示範如何檢視、接受和註冊邀請。以有效的 AWS 帳戶 ID 取代 AWS 帳戶 ID。將 取代`data-share-arn`為參考資料共用的實際 Amazon Resource Name (ARN)。

   1. 檢視待定邀請。

      ```
      aws redshift describe-data-shares \
       --data-share-arn 'arn:aws:redshift:us-east-1:111122223333:datashare:abcd1234-1234-ab12-cd34-1a2b3c4d5e6f/federatedds' \
      ```

   1. 接受資料共用。

      ```
       aws redshift associate-data-share-consumer \
       --data-share-arn 'arn:aws:redshift:us-east-1:111122223333:datashare:abcd1234-1234-ab12-cd34-1a2b3c4d5e6f/federatedds' \
       --consumer-arn 'arn:aws:glue:us-east-1:111122223333:catalog
      ```

   1. 在 Lake Formation 帳戶中註冊資料共用。使用 [RegisterResource](https://docs.aws.amazon.com/lake-formation/latest/APIReference/API_RegisterResource.html) API 操作在 Lake Formation 中註冊資料共用。 `DataShareArn`是 的輸入參數`ResourceArn`。
**注意**  
這是必要步驟。

      ```
      aws lakeformation register-resource \
       --resource-arn 'arn:aws:redshift:us-east-1:111122223333:datashare:abcd1234-1234-ab12-cd34-1a2b3c4d5e6f/federatedds'
      ```

------

1. 建立資料庫。

    接受資料共用邀請後，您需要建立指向與資料共用相關聯之 Amazon Redshift 資料庫的資料庫。您必須是資料湖管理員才能建立資料庫。

------
#### [ Console ]

   1.  從**邀請**窗格中選取資料共用，然後選擇**設定資料庫詳細資訊**。

   1.  在**設定資料庫詳細資訊**中，輸入資料共用的唯一名稱和識別符。您可以使用此識別符在中繼資料階層 (dbName.schema.table).

   1.  選擇**下一步**，將許可授予共用資料庫和資料表上的其他使用者。

------
#### [ AWS CLI ]

    使用下列範例程式碼建立資料庫，該資料庫指向使用 與 Lake Formation 共用的 Amazon Redshift 資料庫 AWS CLI。

   ```
   aws glue create-database --cli-input-json \
   
   '{
    "CatalogId": "111122223333",
    "DatabaseInput": {
     "Name": "tahoedb",
     "FederatedDatabase": {
          "Identifier": "arn:aws:redshift:us-east-1:111122223333:datashare:abcd1234-1234-ab12-cd34-1a2b3c4d5e6f/federatedds",
          "ConnectionName": "aws:redshift"
      }
    }
    }'
   ```

------

1. 授予許可。

    建立資料庫之後，您可以將許可授予帳戶中的使用者，或外部 AWS 帳戶 和組織。您將無法在映射至 Amazon Redshift 資料共用的聯合資料庫上授予寫入資料許可 （插入、刪除） 和中繼資料許可 （變更、捨棄、建立）。如需授予許可的詳細資訊，請參閱 [管理 Lake Formation 許可](managing-permissions.md)。
**注意**  
身為資料湖管理員，您只能檢視聯合資料庫中的資料表。若要執行任何其他動作，您需要對這些資料表授予自己更多許可。

------
#### [ Console ]

   1. 在**授予許可**畫面上，選取要授予許可的使用者。

   1. 選擇 **Grant** (授予)。

------
#### [ AWS CLI ]

   使用下列範例來使用 授予資料庫和資料表許可 AWS CLI：

   ```
   aws lakeformation grant-permissions --input-cli-json file://input.json
   
   {
      "Principal": {
              "DataLakePrincipalIdentifier": "arn:aws:iam::111122223333:user/non-admin"
      },
      "Resource": {
             "Database": {
                   "CatalogId": "111122223333",
                    "Name": "tahoedb"
              }
       },
       "Permissions": [
                "DESCRIBE"
        ],
       "PermissionsWithGrantOption": [
                            
        ]
    }
   ```

   ```
   aws lakeformation grant-permissions --input-cli-json file://input.json
   
   {
                      "Principal": {
                             "DataLakePrincipalIdentifier": "arn:aws:iam::111122223333:user/non-admin"
                      },
                     "Resource": {
                            "Table": {
                                 "CatalogId": "111122223333",
                                 "DatabaseName": "tahoedb",
                                 "Name": "public.customer"
                          }
                     },
                    "Permissions": [
                           "SELECT"
                     ],
                    "PermissionsWithGrantOption": [
                            "SELECT"
                      ]
    }
   ```

------