

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

# 設定跨帳戶擷取的 OpenSearch 擷取管道
<a name="cross-account-pipelines"></a>

對於 HTTP 和 OTel 等推送型來源，Amazon OpenSearch Ingestion 可讓您將管道 AWS 帳戶 從虛擬私有雲端 (VPC) 跨 共用到個別 VPC 中的管道端點。與其組織中的其他團隊共用分析的團隊會使用此功能，以更簡化的方式共用日誌分析。

本節使用以下術語：
+ **管道擁有者** - 擁有和管理 OpenSearch Ingestion 管道的帳戶。只有一個帳戶可以擁有管道。
+ **連線帳戶** — 連線至 並使用共用管道的帳戶。多個帳戶可以連接到相同的管道。

若要設定 VPCs 以跨 共用 OpenSearch Ingestion 管道 AWS 帳戶，請完成下列任務，如此處所述：
+ （管道擁有者） [授予連線帳戶對管道的存取權](#cross-account-pipelines-setting-up-grant-access)
+ （連線帳戶） [為每個連線的 VPC 建立管道端點連線](#cross-account-pipelines-setting-up-create-pipeline-endpoints)

## 開始之前
<a name="cross-account-pipelines-before-you-begin"></a>

設定 VPCs以跨管道共用 OpenSearch Ingestion 管道之前 AWS 帳戶，請完成下列任務：


****  

| 任務 | 詳細資訊 | 
| --- | --- | 
|  建立一或多個 OpenSearch 擷取管道  |  將最小 OpenSearch 運算單位 (OSUs) 設定為 2 或更高。如需詳細資訊，請參閱[建立 Amazon OpenSearch Ingestion 管道](creating-pipeline.md)。如需更新管道的資訊，請參閱 [更新 Amazon OpenSearch 擷取管道](update-pipeline.md)。  | 
|  為 OpenSearch 擷取建立一或多個 VPCs   |  若要啟用跨帳戶管道共用，管道和管道端點涉及的任何 VPC 都必須設定下列 DNS 值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/opensearch-service/latest/developerguide/cross-account-pipelines.html) 如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的 [VPC 的 DNS 屬性](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html)。  | 

## 授予連線帳戶對管道的存取權
<a name="cross-account-pipelines-setting-up-grant-access"></a>

本節中的程序說明如何使用 OpenSearch Service 主控台和 AWS CLI ，透過建立資源政策來設定跨帳戶管道存取。*資源政策*可讓管道擁有者指定可存取管道的其他帳戶。建立之後，只要管道存在或直到刪除政策，管道政策就會存在。

**注意**  
資源政策不會取代使用 [IAM 許可](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/creating-pipeline.html#create-pipeline-permissions)的標準 OpenSearch Ingestion 授權。資源政策是用於啟用跨帳戶管道存取的新增授權機制。

**Topics**
+ [授予連線帳戶對管道的存取權 （主控台）](#cross-account-pipelines-setting-up-grant-access-console)
+ [授予連線帳戶對管道的存取權 (CLI)](#cross-account-pipelines-setting-up-grant-access-cli)

### 授予連線帳戶對管道的存取權 （主控台）
<a name="cross-account-pipelines-setting-up-grant-access-console"></a>

使用下列程序，透過 Amazon OpenSearch Service 主控台授予連線帳戶對管道的存取權。

**建立管道端點連線**

1. 在 Amazon OpenSearch Service 主控台的導覽窗格中，展開**擷取**，然後選取**管道**。

1. 在**管道**區段中，選擇您要授予連線帳戶存取權的管道名稱。

1. 選擇 **VPC 端點**索引標籤。

1. 在**授權委託人**區段中，選擇**授權帳戶**。

1. 在 **AWS 帳戶 ID** 欄位中，輸入 12 位數的帳戶 ID，然後選取**授權**。

### 授予連線帳戶對管道的存取權 (CLI)
<a name="cross-account-pipelines-setting-up-grant-access-cli"></a>

使用下列程序，透過 授予連線帳戶對管道的存取權 AWS CLI。

**授予連線帳戶對管道的存取權**

1. 更新至最新版本的 AWS CLI (2.0 版）。如需詳細資訊，請參閱[安裝或更新至最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 在帳戶中開啟 CLI， AWS 區域 並使用您要共用的管道。

1. 執行下列命令來建立管道的資源政策。此政策提供管道的 `osis:CreatePipelineEndpoint` 許可。政策包含參數，您可以在其中列出要允許的 AWS 帳戶 IDs。
**注意**  
在下列命令中，您必須僅提供 12 位數帳戶 ID，以使用簡短形式的帳戶 ID。使用 ARN 將無法運作。您還必須在 的 CLI 參數和 下的政策 JSON `resource-arn`中提供管道的 Amazon Resource Name (ARN)`Resource`，如下所示。

   ```
   aws --region region osis put-resource-policy \
     --resource-arn arn:aws:osis:region:pipeline-owner-account-ID:pipeline/pipeline-name
     --policy 'IAM-policy'
   ```

   針對 *IAM-policy* 使用類似下列的政策

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

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
     {
     "Sid": "AllowAccess",
     "Effect": "Allow",
     "Principal": {
     "AWS": [
     "111122223333",
     "444455556666"
     ]
     },
     "Action": 
     "osis:CreatePipelineEndpoint",
     "Resource": "arn:aws:osis:us-east-1:123456789012:pipeline/pipeline-name"
     }
     ]
    }
   ```

------

## 為每個連線的 VPC 建立管道端點連線
<a name="cross-account-pipelines-setting-up-create-pipeline-endpoints"></a>

管道擁有者使用先前的程序授予其 VPC 中管道的存取權後，連線帳戶中的使用者會在其 VPC 中建立管道端點。本節包含使用 OpenSearch Service 主控台和 建立端點的程序 AWS CLI。當您建立端點時，OpenSearch Ingestion 會執行下列動作：
+ 如果 [AWSServiceRoleForAmazonOpenSearchIngestionService](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/slr-osis.html) 服務連結角色不存在，請在您的帳戶中建立該角色。此角色授予連線帳戶中的使用者呼叫 [CreatePipelineEndpoint](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_osis_CreatePipelineEndpoint.html) API 動作的許可。
+ 建立管道端點。
+ 設定管道端點，從管道擁有者 VPC 中的共用管道擷取資料。

**Topics**
+ [建立管道端點連線 （主控台）](#cross-account-pipelines-setting-up-create-pipeline-endpoints-console)
+ [建立管道端點連線 (CLI)](#cross-account-pipelines-setting-up-create-pipeline-endpoints-cli)

### 建立管道端點連線 （主控台）
<a name="cross-account-pipelines-setting-up-create-pipeline-endpoints-console"></a>

使用下列程序，透過 OpenSearch Service 主控台建立管道端點連線。

**建立管道端點連線**

1. 在 Amazon OpenSearch Service 主控台的導覽窗格中，展開**擷取**，然後選取 **VPC 端點**。

1. 在 **VPC 端點**頁面中，選擇**建立**。

1. 針對**管道位置**，選擇選項。如果您選擇**目前帳戶**，請從清單中選擇管道。如果您選擇**跨帳戶**，請在 欄位中指定管道 ARN。管道擁有者必須已授予管道的存取權，如中所述[授予連線帳戶對管道的存取權](#cross-account-pipelines-setting-up-grant-access)。

1. 在 **VPC 設定**區段中，針對 **VPC**，從清單中選擇 VPC。

1. 針對 **Subnet (子網路)**，請選擇子網路。

1. 針對**安全群組**，選擇群組。

1. 選擇**建立端點**。

等待您建立的端點狀態轉換為 `ACTIVE`。一旦管道為 `ACTIVE`，您會看到名為 的新欄位`ingestEndpointUrl`。使用此端點來存取管道，並使用 FluentBit 等用戶端擷取資料。如需使用 FluentBit 擷取資料的詳細資訊，請參閱 [搭配 Fluent Bit 使用 OpenSearch 擷取管道](configure-client-fluentbit.md)。

**注意**  
`ingestEndpointUrl` 是所有連線帳戶的相同 URL。

### 建立管道端點連線 (CLI)
<a name="cross-account-pipelines-setting-up-create-pipeline-endpoints-cli"></a>

使用下列程序，使用 建立管道端點連線 AWS CLI。

**建立管道端點連線**

1. 如果您尚未更新至最新版本的 AWS CLI (2.0 版）。如需詳細資訊，請參閱[安裝或更新至最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 使用共用管道在 中的連線帳戶中開啟 AWS 區域 CLI。

1. 執行下列命令來建立管道端點。
**注意**  
您必須為連線帳戶 VPC 提供至少一個子網路和一個安全群組。安全群組必須包含連接埠 443，並在連線帳戶 VPC 中支援用戶端。

   ```
   aws osis --region region create-pipeline-endpoint \
     --pipeline-arn arn:aws:osis:region:connecting-account-ID:pipeline/shared-pipeline-name
     --vpc-options SecurityGroupIds={sg-security-group-ID-1,sg-security-group-ID-2},SubnetIds=subnet-subnet-ID
   ```

1. 執行下列命令，列出在上一個命令中指定的區域中的端點：

   ```
   aws osis --region region list-pipeline-endpoints
   ```

等待您建立的端點狀態轉換為 `ACTIVE`。一旦管道為 `ACTIVE`，您會看到名為 的新欄位`ingestEndpointUrl`。使用此端點來存取管道，並使用 FluentBit 等用戶端擷取資料。如需使用 FluentBit 擷取資料的詳細資訊，請參閱 [搭配 Fluent Bit 使用 OpenSearch 擷取管道](configure-client-fluentbit.md)。

**注意**  
`ingestEndpointUrl` 是所有連線帳戶的相同 URL。

## 移除管道端點
<a name="cross-account-pipelines-remove"></a>

如果您不想再提供共用管道的存取權，您可以使用下列其中一種方法移除管道端點：
+ 刪除管道端點 （連線帳戶）。
+ 撤銷管道端點 （管道擁有者）。

使用下列程序刪除連線帳戶中的管道端點。

**刪除管道端點 （連線帳戶）**

1. 使用共用管道在 中的連線帳戶中開啟 AWS 區域 CLI。

1. 執行下列命令，列出 區域中的管道端點：

   ```
   aws osis --region region list-pipeline-endpoints
   ```

   記下您要刪除的管道 ID。

1. 執行下列命令來刪除管道端點：

   ```
   aws osis --region region delete-pipeline-endpoint \
     --endpoint-id 'ID'
   ```

身為共用管道的管道擁有者，請使用下列程序來撤銷管道端點。

**撤銷管道端點 （管道擁有者）**

1. 使用共用管道在 中的連線帳戶中開啟 AWS 區域 CLI。

1. 執行下列命令，列出 區域中的管道端點連線：

   ```
   aws osis --region region list-pipeline-endpoint-connections
   ```

   記下您要刪除的管道 ID。

1. 執行下列命令來刪除管道端點：

   ```
   aws osis --region region revoke-pipeline-endpoint-connections \
     --pipeline-arn pipeline-arn --endpoint-ids ID
   ```

   命令僅支援指定一個端點 ID。