

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

# OpenSearch 網域的跨區域資料存取
<a name="application-cross-region-data-access-domains"></a>

您可以在一個 中設定 OpenSearch UI 應用程式 AWS 區域 ，以存取不同 AWS 區域中的 OpenSearch 網域。這可讓您建立統一的儀表板，將來自 OpenSearch 網域的資料彙總到相同分割區中的多個 AWS 區域。跨區域資料來源支援需要在目標網域上啟用精細存取控制。精細存取控制提供網域存取政策以外的額外授權層，可讓您控制對個別索引、文件和欄位的存取。

## 重要概念
<a name="cross-region-key-concepts"></a>

應用程式區域  
OpenSearch UI 應用程式託管 AWS 區域 所在的 。

目標區域  
 AWS 區域 OpenSearch 網域所在的 。這可以是相同分割區中的任何區域，無論該區域中是否提供 OpenSearch UI。

跨帳戶角色  
目標帳戶中的 IAM 角色，僅在資料來源關聯期間使用。OpenSearch UI 會擔任此角色來呼叫 `es:DescribeDomain`，這會擷取網域端點並驗證是否已啟用精細存取控制。只有在網域位於與應用程式不同的帳戶中時，才需要此角色。如需詳細資訊，請參閱[跨帳戶資料存取 OpenSearch 網域](application-cross-account-data-access-domains.md)。

IAM Identity Center 應用程式角色  
應用程式帳戶中的 IAM 角色，用於 IAM Identity Center 使用者資料平面存取。

支援的區域 （適用於 VPC 網域）  
對於 VPC 網域，您必須在授權 VPC 端點時允許列出託管 OpenSearch UI 應用程式的 AWS 區域。需要此允許清單，以便 OpenSearch UI 可以呼叫 VPC 網域。

## 先決條件
<a name="cross-region-prerequisites"></a>

設定跨區域資料存取之前，請確定您有下列項目：
+ AWS CLI 已安裝和設定
+ 在 AWS 帳戶 應用程式區域和目標區域中存取
+ 已啟用精細存取控制的 OpenSearch 網域。只有已啟用精細存取控制的網域才支援多區域資料來源關聯。
+ 對於跨帳戶案例：同時存取來源和目標 AWS 帳戶
+ 對於 IAM Identity Center 流程： AWS IAM Identity Center 組織執行個體。OpenSearch UI 應用程式必須與 IAM Identity Center 執行個體位於相同的區域。

## 案例
<a name="cross-region-scenarios"></a>

選擇符合您身分驗證方法和網域組態的案例：
+ [案例 1：存取不同區域中公有網域的 IAM 使用者](#cross-region-scenario-1)
+ [案例 2：存取不同區域中公有網域的 IAM Identity Center 使用者](#cross-region-scenario-2)
+ [案例 3：存取不同區域中 VPC 網域的 IAM 使用者](#cross-region-scenario-3)
+ [案例 4：存取不同區域中 VPC 網域的 IAM Identity Center 使用者](#cross-region-scenario-4)

每個案例都涵蓋相同帳戶跨區域存取。對於跨帳戶跨區域存取，請將這些案例中的步驟與 中所述的跨帳戶角色設定合併[跨帳戶資料存取 OpenSearch 網域](application-cross-account-data-access-domains.md)。

## 案例 1：存取不同區域中公有網域的 IAM 使用者
<a name="cross-region-scenario-1"></a>

在此案例中，您會在一個區域中建立 OpenSearch UI 應用程式，並將其連接到相同帳戶中不同區域中的公有 OpenSearch 網域。

### 步驟 1：建立 OpenSearch 網域 （目標區域）
<a name="cross-region-scenario-1-step-1"></a>

在已啟用精細存取控制的目標區域中建立 OpenSearch 網域。將存取政策範圍限定為帳戶根或特定 IAM 主體。

```
aws opensearch create-domain \
  --domain-name {{domain-name}} \
  --engine-version OpenSearch_2.19 \
  --cluster-config InstanceType=m5.large.search,InstanceCount=1 \
  --ebs-options "EBSEnabled=true,VolumeType=gp3,VolumeSize=100" \
  --advanced-security-options '{"Enabled":true,"InternalUserDatabaseEnabled":true,"MasterUserOptions":{"MasterUserName":"{{admin}}","MasterUserPassword":"{{master-password}}"}}' \
  --node-to-node-encryption-options '{"Enabled":true}' \
  --encryption-at-rest-options '{"Enabled":true}' \
  --domain-endpoint-options '{"EnforceHTTPS":true,"TLSSecurityPolicy":"Policy-Min-TLS-1-2-2019-07"}' \
  --access-policies '{"Version":"2012-10-17",		 	 	 "Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::{{account-id}}:root"},"Action":"es:ESHttp*","Resource":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{domain-name}}/*"}]}' \
  --region {{target-region}}
```

等待網域狀態變為 ，`Active`再繼續。

### 步驟 2：建立 OpenSearch UI 應用程式 （應用程式區域）
<a name="cross-region-scenario-1-step-2"></a>

使用跨區域資料來源在應用程式區域中建立應用程式。區域會自動從資料來源 ARN 擷取。

```
aws opensearch create-application \
  --region {{application-region}} \
  --name "{{cross-region-iam-app}}" \
  --data-sources '[{
    "dataSourceArn":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{domain-name}}",
    "dataSourceDescription":"{{Cross-region domain}}"
  }]' \
  --app-configs '[{"key":"opensearchDashboards.dashboardAdmin.users","value":"[\"{{test-user}}\"]"}]'
```

### 步驟 3：驗證和存取
<a name="cross-region-scenario-1-step-3"></a>

擷取應用程式詳細資訊以取得端點 URL：

```
aws opensearch get-application \
  --region {{application-region}} \
  --id {{application-id}}
```
+ 從回應導覽至應用程式端點 URL。
+ 使用 IAM 登入資料登入。
+ IAM 使用者使用自己的登入資料簽署資料平面請求。
+ 目標網域的存取政策和後端角色映射控制使用者可以存取哪些資料。

## 案例 2：存取不同區域中公有網域的 IAM Identity Center 使用者
<a name="cross-region-scenario-2"></a>

在此案例中，您會在一個區域中使用 IAM Identity Center 身分驗證建立 OpenSearch UI 應用程式，並將其連接到相同帳戶中不同區域中的公有 OpenSearch 網域。

### 步驟 1：建立已啟用 IAM Identity Center 的 OpenSearch 網域 （目標區域）
<a name="cross-region-scenario-2-step-1"></a>

在啟用精細存取控制和 IAM Identity Center 整合的目標區域中建立 OpenSearch 網域。使用 `--identity-center-options` 參數搭配 `IdentityCenterInstanceRegion` 來指定 IAM Identity Center 執行個體所在的區域。此區域應與託管 OpenSearch UI 應用程式的位置相同。

```
aws opensearch create-domain \
  --domain-name {{domain-name}} \
  --engine-version OpenSearch_2.19 \
  --cluster-config InstanceType=m5.large.search,InstanceCount=1 \
  --ebs-options "EBSEnabled=true,VolumeType=gp3,VolumeSize=100" \
  --advanced-security-options '{"Enabled":true,"InternalUserDatabaseEnabled":true,"MasterUserOptions":{"MasterUserName":"{{admin}}","MasterUserPassword":"{{master-password}}"}}' \
  --node-to-node-encryption-options '{"Enabled":true}' \
  --encryption-at-rest-options '{"Enabled":true}' \
  --domain-endpoint-options '{"EnforceHTTPS":true,"TLSSecurityPolicy":"Policy-Min-TLS-1-2-2019-07"}' \
  --identity-center-options '{"EnabledAPIAccess":true,"IdentityCenterInstanceARN":"arn:aws:sso:::instance/ssoins-{{instance-id}}","IdentityCenterInstanceRegion":"{{idc-region}}","RolesKey":"GroupId","SubjectKey":"UserId"}' \
  --access-policies '{"Version":"2012-10-17",		 	 	 "Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::{{account-id}}:role/{{NeoIdCAppRole}}"},"Action":"es:ESHttp*","Resource":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{domain-name}}/*"}]}' \
  --region {{target-region}}
```

等待網域狀態變為 ，`Active`再繼續。

### 步驟 2：為 IAM Identity Center 應用程式建立 IAM 角色
<a name="cross-region-scenario-2-step-2"></a>

建立 OpenSearch UI 用於 IAM Identity Center 使用者資料平面存取的 IAM 角色。

**建立 IAM Identity Center 應用程式角色**

1. 建立僅包含 `sts:AssumeRole`陳述式的信任政策。在下一個步驟中建立應用程式後，您將更新此政策以新增 `sts:SetContext`陳述式。

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "Service": "application.opensearchservice.amazonaws.com"
         },
         "Action": "sts:AssumeRole"
       }
     ]
   }
   ```

1. 建立許可政策：

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [{
       "Sid": "OpenSearchDomain",
       "Effect": "Allow",
       "Action": ["es:ESHttp*"],
       "Resource": "arn:aws:es:{{target-region}}:{{account-id}}:domain/{{domain-name}}/*"
     }]
   }
   ```

1. 建立角色並連接政策：

   ```
   aws iam create-role \
     --role-name {{NeoIdCAppRole}} \
     --assume-role-policy-document file://{{neoidc-trust-policy.json}}
   
   aws iam put-role-policy \
     --role-name {{NeoIdCAppRole}} \
     --policy-name {{NeoIdCAppPermissions}} \
     --policy-document file://{{neoidc-permissions-policy.json}}
   ```

### 步驟 3：使用 IAM Identity Center 建立 OpenSearch UI 應用程式 （應用程式區域）
<a name="cross-region-scenario-2-step-3"></a>

**注意**  
確保 IAM Identity Center 執行個體與 OpenSearch UI 應用程式區域位於相同的區域。

```
aws opensearch create-application \
  --region {{application-region}} \
  --name "{{cross-region-idc-app}}" \
  --iam-identity-center-options '{
    "enabled":true,
    "iamIdentityCenterInstanceArn":"arn:aws:sso:::instance/ssoins-{{instance-id}}",
    "iamRoleForIdentityCenterApplicationArn":"arn:aws:iam::{{account-id}}:role/{{NeoIdCAppRole}}"
  }' \
  --data-sources '[{
    "dataSourceArn":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{domain-name}}",
    "dataSourceDescription":"{{Cross-region domain}}"
  }]' \
  --app-configs '[{"key":"opensearchDashboards.dashboardAdmin.users","value":"[\"{{test-user}}\"]"}]'
```

建立應用程式後，請注意回應中的 SSO 應用程式 ID。然後更新 IAM Identity Center 應用程式角色上的信任政策，以新增`sts:SetContext`陳述式：

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "application.opensearchservice.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "application.opensearchservice.amazonaws.com"
      },
      "Action": "sts:SetContext",
      "Condition": {
        "ForAllValues:ArnEquals": {
          "sts:RequestContextProviders": "arn:aws:iam::{{account-id}}:oidc-provider/portal.sso.{{idc-region}}.amazonaws.com/apl/{{application-id}}"
        }
      }
    }
  ]
}
```

```
aws iam update-assume-role-policy \
  --role-name {{NeoIdCAppRole}} \
  --policy-document file://{{updated-trust-policy.json}}
```

### 步驟 4：建立和指派 IAM Identity Center 使用者和群組
<a name="cross-region-scenario-2-step-4"></a>

**建立 IAM Identity Center 使用者**  
執行下列命令。使用您的資訊取代{{預留位置的值}}。

```
aws identitystore create-user \
  --identity-store-id {{d-directory-id}} \
  --user-name {{user-email}} \
  --display-name "{{display-name}}" \
  --name Formatted=string,FamilyName={{last-name}},GivenName={{first-name}} \
  --emails Value={{user-email}},Type=work,Primary=true
```

**建立 IAM Identity Center 群組並新增使用者**  
執行下列命令：

```
aws identitystore create-group \
  --identity-store-id {{d-directory-id}} \
  --display-name "{{OpenSearchUsers}}" \
  --description "{{Users with OpenSearch access}}"

aws identitystore create-group-membership \
  --identity-store-id {{d-directory-id}} \
  --group-id {{group-id}} \
  --member-id UserId={{user-id}}
```

**將使用者或群組指派給應用程式**  
執行以下命令：

```
aws sso-admin create-application-assignment \
  --application-arn "arn:aws:sso::{{account-id}}:application/ssoins-{{instance-id}}/apl-{{application-id}}" \
  --principal-id {{user-id-or-group-id}} \
  --principal-type {{USER}}
```

**在目標網域上設定後端角色映射**  
將 IAM Identity Center 群組映射至目標網域上的 OpenSearch 安全角色：

```
curl -XPATCH "https://{{domain-endpoint}}/_plugins/_security/api/rolesmapping/all_access" \
  -u {{admin}}:{{master-password}} \
  -H 'Content-Type: application/json' \
  -d '[{"op": "add", "path": "/backend_roles", "value": ["{{group-id}}"]}]'
```

### 步驟 5：驗證和存取
<a name="cross-region-scenario-2-step-5"></a>

擷取應用程式詳細資訊以取得端點 URL：

```
aws opensearch get-application \
  --region {{application-region}} \
  --id {{application-id}}
```
+ 導覽至應用程式端點 URL。
+ 使用 IAM Identity Center 使用者憑證登入。
+ IAM Identity Center 使用者的資料請求會使用 IAM Identity Center 應用程式角色簽署。
+ 網域控制資料存取許可上的後端角色映射。

## 案例 3：存取不同區域中 VPC 網域的 IAM 使用者
<a name="cross-region-scenario-3"></a>

在此案例中，您會在一個區域中建立 OpenSearch UI 應用程式，並將其連接到相同帳戶中不同區域中的 VPC OpenSearch 網域。VPC 網域需要額外的網路組態和具有跨區域支援的明確 VPC 端點授權。

### 步驟 1：設定 VPC （目標區域）
<a name="cross-region-scenario-3-step-1"></a>

如果目標區域中已存在 VPC，請略過此步驟。

```
# Create VPC
aws ec2 create-vpc \
  --cidr-block 10.0.0.0/16 \
  --region {{target-region}}

# Create subnet
aws ec2 create-subnet \
  --vpc-id {{vpc-id}} \
  --cidr-block 10.0.1.0/24 \
  --availability-zone {{target-region}}a \
  --region {{target-region}}

# Create security group
aws ec2 create-security-group \
  --group-name {{opensearch-vpc-sg}} \
  --description "Security group for OpenSearch VPC domain" \
  --vpc-id {{vpc-id}} \
  --region {{target-region}}

# Allow inbound HTTPS
aws ec2 authorize-security-group-ingress \
  --group-id {{security-group-id}} \
  --protocol tcp \
  --port 443 \
  --cidr 10.0.0.0/16 \
  --region {{target-region}}
```

進一步了解 [VPC 網域建立](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/vpc.html)。

### 步驟 2：建立 VPC 網域 （目標區域）
<a name="cross-region-scenario-3-step-2"></a>

```
aws opensearch create-domain \
  --domain-name {{vpc-domain-name}} \
  --engine-version OpenSearch_2.19 \
  --cluster-config InstanceType=m5.large.search,InstanceCount=1 \
  --ebs-options "EBSEnabled=true,VolumeType=gp3,VolumeSize=100" \
  --vpc-options "SubnetIds={{subnet-id}},SecurityGroupIds={{security-group-id}}" \
  --advanced-security-options '{"Enabled":true,"InternalUserDatabaseEnabled":true,"MasterUserOptions":{"MasterUserName":"{{admin}}","MasterUserPassword":"{{master-password}}"}}' \
  --node-to-node-encryption-options '{"Enabled":true}' \
  --encryption-at-rest-options '{"Enabled":true}' \
  --domain-endpoint-options '{"EnforceHTTPS":true,"TLSSecurityPolicy":"Policy-Min-TLS-1-2-2019-07"}' \
  --access-policies '{"Version":"2012-10-17",		 	 	 "Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::{{account-id}}:root"},"Action":"es:ESHttp*","Resource":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{vpc-domain-name}}/*"}]}' \
  --region {{target-region}}
```

等待網域狀態變為 ，`Active`再繼續。

### 步驟 3：使用跨區域支援 （目標區域） 授權 OpenSearch UI 服務主體的 VPC 端點
<a name="cross-region-scenario-3-step-3"></a>

```
# Authorize the service principal with cross-region support
aws opensearch authorize-vpc-endpoint-access \
  --domain-name {{vpc-domain-name}} \
  --service "application.opensearchservice.amazonaws.com" \
  --service-options '{"SupportedRegions":["{{target-region}}","{{application-region}}"]}' \
  --region {{target-region}}

# Verify authorization
aws opensearch list-vpc-endpoint-access \
  --domain-name {{vpc-domain-name}} \
  --region {{target-region}}
```

預期回應：

```
{
  "AuthorizedPrincipalList": [
    {
      "PrincipalType": "AWS_SERVICE",
      "Principal": "application.opensearchservice.amazonaws.com",
      "ServiceOptions": {
        "SupportedRegions": ["{{target-region}}", "{{application-region}}"]
      }
    }
  ]
}
```

### 步驟 4：建立 OpenSearch UI 應用程式 （應用程式區域）
<a name="cross-region-scenario-3-step-4"></a>

```
aws opensearch create-application \
  --region {{application-region}} \
  --name "{{cross-region-vpc-iam-app}}" \
  --data-sources '[{
    "dataSourceArn":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{vpc-domain-name}}",
    "dataSourceDescription":"{{Cross-region VPC domain}}"
  }]' \
  --app-configs '[{"key":"opensearchDashboards.dashboardAdmin.users","value":"[\"{{test-user}}\"]"}]'
```

### 步驟 5：驗證和存取
<a name="cross-region-scenario-3-step-5"></a>

擷取應用程式詳細資訊以取得端點 URL：

```
aws opensearch get-application \
  --region {{application-region}} \
  --id {{application-id}}
```
+ 從回應導覽至應用程式端點 URL。
+ 使用 IAM 登入資料登入。
+ IAM 使用者使用自己的登入資料簽署資料平面請求。
+ 目標網域的存取政策和後端角色映射控制使用者可以存取哪些資料。

## 案例 4：存取不同區域中 VPC 網域的 IAM Identity Center 使用者
<a name="cross-region-scenario-4"></a>

在此案例中，您會在一個區域中使用 IAM Identity Center 身分驗證建立 OpenSearch UI 應用程式，並將其連接到相同帳戶中不同區域中的 VPC OpenSearch 網域。

### 步驟 1：設定 VPC （目標區域）
<a name="cross-region-scenario-4-step-1"></a>

如果目標區域中已存在 VPC，請略過此步驟。

```
# Create VPC
aws ec2 create-vpc \
  --cidr-block 10.0.0.0/16 \
  --region {{target-region}}

# Create subnet
aws ec2 create-subnet \
  --vpc-id {{vpc-id}} \
  --cidr-block 10.0.1.0/24 \
  --availability-zone {{target-region}}a \
  --region {{target-region}}

# Create security group
aws ec2 create-security-group \
  --group-name {{opensearch-vpc-sg}} \
  --description "Security group for OpenSearch VPC domain" \
  --vpc-id {{vpc-id}} \
  --region {{target-region}}

# Allow inbound HTTPS
aws ec2 authorize-security-group-ingress \
  --group-id {{security-group-id}} \
  --protocol tcp \
  --port 443 \
  --cidr 10.0.0.0/16 \
  --region {{target-region}}
```

進一步了解 [VPC 網域建立](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/vpc.html)。

### 步驟 2：建立已啟用 IAM Identity Center 的 VPC 網域 （目標區域）
<a name="cross-region-scenario-4-step-2"></a>

在已啟用精細存取控制、IAM Identity Center 整合和 VPC 組態的目標區域中建立 OpenSearch 網域。更新存取政策以允許 IAM Identity Center 應用程式角色並新增 `--identity-center-options` 參數：

```
aws opensearch create-domain \
  --domain-name {{vpc-domain-name}} \
  --engine-version OpenSearch_2.19 \
  --cluster-config InstanceType=m5.large.search,InstanceCount=1 \
  --ebs-options "EBSEnabled=true,VolumeType=gp3,VolumeSize=100" \
  --vpc-options "SubnetIds={{subnet-id}},SecurityGroupIds={{security-group-id}}" \
  --advanced-security-options '{"Enabled":true,"InternalUserDatabaseEnabled":true,"MasterUserOptions":{"MasterUserName":"{{admin}}","MasterUserPassword":"{{master-password}}"}}' \
  --node-to-node-encryption-options '{"Enabled":true}' \
  --encryption-at-rest-options '{"Enabled":true}' \
  --domain-endpoint-options '{"EnforceHTTPS":true,"TLSSecurityPolicy":"Policy-Min-TLS-1-2-2019-07"}' \
  --identity-center-options '{"EnabledAPIAccess":true,"IdentityCenterInstanceARN":"arn:aws:sso:::instance/ssoins-{{instance-id}}","IdentityCenterInstanceRegion":"{{idc-region}}","RolesKey":"GroupId","SubjectKey":"UserId"}' \
  --access-policies '{"Version":"2012-10-17",		 	 	 "Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::{{account-id}}:role/{{NeoIdCAppRole}}"},"Action":"es:ESHttp*","Resource":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{vpc-domain-name}}/*"}]}' \
  --region {{target-region}}
```

等待網域狀態變為 ，`Active`再繼續。

### 步驟 3：使用跨區域支援 （目標區域） 授權 OpenSearch UI 服務主體的 VPC 端點
<a name="cross-region-scenario-4-step-3"></a>

**重要**  
這是具有跨區域存取的 VPC 網域唯一的關鍵步驟。OpenSearch UI 服務必須明確授權才能存取 VPC 端點，而且您必須在`SupportedRegions`清單中包含應用程式區域。

```
# Authorize the service principal with cross-region support
aws opensearch authorize-vpc-endpoint-access \
  --domain-name {{vpc-domain-name}} \
  --service "application.opensearchservice.amazonaws.com" \
  --service-options '{"SupportedRegions":["{{target-region}}","{{application-region}}"]}' \
  --region {{target-region}}

# Verify authorization
aws opensearch list-vpc-endpoint-access \
  --domain-name {{vpc-domain-name}} \
  --region {{target-region}}
```

預期回應：

```
{
  "AuthorizedPrincipalList": [
    {
      "PrincipalType": "AWS_SERVICE",
      "Principal": "application.opensearchservice.amazonaws.com",
      "ServiceOptions": {
        "SupportedRegions": ["{{target-region}}", "{{application-region}}"]
      }
    }
  ]
}
```

### 步驟 4：為 IAM Identity Center 應用程式建立 IAM 角色
<a name="cross-region-scenario-4-step-4"></a>

建立 OpenSearch UI 用於 IAM Identity Center 使用者資料平面存取的 IAM 角色。

**建立 IAM Identity Center 應用程式角色**

1. 建立僅包含 `sts:AssumeRole`陳述式的信任政策。在下一個步驟中建立應用程式後，您將更新此政策以新增 `sts:SetContext`陳述式。

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "Service": "application.opensearchservice.amazonaws.com"
         },
         "Action": "sts:AssumeRole"
       }
     ]
   }
   ```

1. 建立許可政策：

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [{
       "Sid": "OpenSearchDomain",
       "Effect": "Allow",
       "Action": ["es:ESHttp*"],
       "Resource": "arn:aws:es:{{target-region}}:{{account-id}}:domain/{{vpc-domain-name}}/*"
     }]
   }
   ```

1. 建立角色並連接政策：

   ```
   aws iam create-role \
     --role-name {{NeoIdCAppRole}} \
     --assume-role-policy-document file://{{neoidc-trust-policy.json}}
   
   aws iam put-role-policy \
     --role-name {{NeoIdCAppRole}} \
     --policy-name {{NeoIdCAppPermissions}} \
     --policy-document file://{{neoidc-permissions-policy.json}}
   ```

### 步驟 5：使用 IAM Identity Center 建立 OpenSearch UI 應用程式 （應用程式區域）
<a name="cross-region-scenario-4-step-5"></a>

```
aws opensearch create-application \
  --region {{application-region}} \
  --name "{{cross-region-vpc-idc-app}}" \
  --iam-identity-center-options '{
    "enabled":true,
    "iamIdentityCenterInstanceArn":"arn:aws:sso:::instance/ssoins-{{instance-id}}",
    "iamRoleForIdentityCenterApplicationArn":"arn:aws:iam::{{account-id}}:role/{{NeoIdCAppRole}}"
  }' \
  --data-sources '[{
    "dataSourceArn":"arn:aws:es:{{target-region}}:{{account-id}}:domain/{{vpc-domain-name}}",
    "dataSourceDescription":"{{Cross-region VPC domain}}"
  }]' \
  --app-configs '[{"key":"opensearchDashboards.dashboardAdmin.users","value":"[\"{{test-user}}\"]"}]'
```

建立應用程式後，請注意回應中的 SSO 應用程式 ID。然後更新 IAM Identity Center 應用程式角色上的信任政策，以新增`sts:SetContext`陳述式：

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "application.opensearchservice.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "application.opensearchservice.amazonaws.com"
      },
      "Action": "sts:SetContext",
      "Condition": {
        "ForAllValues:ArnEquals": {
          "sts:RequestContextProviders": "arn:aws:iam::{{account-id}}:oidc-provider/portal.sso.{{idc-region}}.amazonaws.com/apl/{{application-id}}"
        }
      }
    }
  ]
}
```

```
aws iam update-assume-role-policy \
  --role-name {{NeoIdCAppRole}} \
  --policy-document file://{{updated-trust-policy.json}}
```

### 步驟 6：建立和指派 IAM Identity Center 使用者和群組
<a name="cross-region-scenario-4-step-6"></a>

請遵循與[步驟 4：建立和指派 IAM Identity Center 使用者和群組](#cross-region-scenario-2-step-4)建立使用者、群組、將其指派給應用程式，以及在目標網域上設定後端角色映射相同的步驟。

### 步驟 7：驗證和存取
<a name="cross-region-scenario-4-step-7"></a>

擷取應用程式詳細資訊以取得端點 URL：

```
aws opensearch get-application \
  --region {{application-region}} \
  --id {{application-id}}
```
+ 導覽至應用程式端點 URL。
+ 使用 IAM Identity Center 使用者憑證登入。
+ IAM Identity Center 使用者的資料請求會使用 IAM Identity Center 應用程式角色簽署。
+ 網域控制資料存取許可上的後端角色映射。

## 管理 應用程式
<a name="cross-region-managing-applications"></a>

**使用跨區域資料來源更新應用程式**  
執行下列命令。使用您的資訊取代{{預留位置的值}}。

```
aws opensearch update-application \
  --region {{application-region}} \
  --id {{application-id}} \
  --data-sources '[{
    "dataSourceArn":"arn:aws:es:{{target-region-1}}:{{account-id}}:domain/{{domain-1}}",
    "dataSourceDescription":"{{Domain in target Region 1}}"
  },{
    "dataSourceArn":"arn:aws:es:{{target-region-2}}:{{account-id}}:domain/{{domain-2}}",
    "dataSourceDescription":"{{Domain in target Region 2}}"
  }]'
```

**重要**  
更新操作會取代整個資料來源陣列。包含您要保留的所有資料來源。

**列出應用程式**  
執行以下命令：

```
aws opensearch list-applications \
  --region {{application-region}}
```

**刪除應用程式**  
執行以下命令：

```
aws opensearch delete-application \
  --region {{application-region}} \
  --id {{application-id}}
```

**撤銷特定區域的 VPC 端點存取權**  
若要撤銷特定 的跨區域存取權，同時保留其他 AWS 區域，請使用 `--service-options` 參數搭配 區域來撤銷：

```
aws opensearch revoke-vpc-endpoint-access \
  --domain-name {{vpc-domain-name}} \
  --service "application.opensearchservice.amazonaws.com" \
  --service-options '{"SupportedRegions":["{{region-to-revoke}}"]}' \
  --region {{target-region}}
```

## 快速參考
<a name="cross-region-quick-reference"></a>

下表摘要說明網域類型、身分驗證方法和相同區域與跨區域存取之間的主要差異。


**公有網域與 VPC 網域的比較**  

| 面向 | 公有網域 | VPC 網域 | 
| --- | --- | --- | 
| VPC 端點授權 | 非必要 | 必要 – 必須使用 application.opensearchservice.amazonaws.com 授權 SupportedRegions | 
| 網路設定 | 無 | VPC、子網路、具有 HTTPS (443) 傳入的安全群組 | 
| IAM 存取政策 | 必要 | 必要 | 


**IAM 使用者與 IAM Identity Center 使用者相比**  

| 面向 | IAM 使用者 | IAM Identity Center 使用者 | 
| --- | --- | --- | 
| 資料平面登入資料 | 使用者自己的 IAM 登入資料 | IAM Identity Center 應用程式角色 | 
| 存取控制 | 網域存取政策和後端角色映射 | 網域存取政策和後端角色映射 | 
| 應用程式區域限制條件 | 任何區域 | 必須與 IAM Identity Center 執行個體位於相同的區域 | 
| 網域組態 | 標準 | --identity-center-options 使用 需要 IdentityCenterInstanceRegion | 
| 其他設定 | 無 | IAM Identity Center 應用程式角色、使用者/群組建立、應用程式指派、後端角色映射 | 


**與跨區域相比的區域相同**  

| 面向 | 相同區域 | 跨區域 | 
| --- | --- | --- | 
| 資料來源 ARN | 與應用程式相同的區域 | 與應用程式不同的區域 （相同分割區） | 
| VPC 端點授權 | 省略 --service-options | 包含 --service-options與 SupportedRegions | 
| IAM Identity Center 網域組態 | IdentityCenterInstanceRegion 選用 | IdentityCenterInstanceRegion 必要 | 
| 跨分割區支援 | N/A | 不支援 – 資料來源必須位於相同的分割區 | 

## 重要說明
<a name="cross-region-important-notes"></a>
+ 跨區域資料來源關聯需要在目標網域上啟用精細存取控制。
+ 跨區域資料來源必須位於相同的分割區內。不支援跨分割區存取 （例如，從 `aws`到 `aws-cn`)。
+ 資料來源區域會自動從資料來源 ARN 擷取。`CreateApplication` 或 `UpdateApplication` APIs 中不需要額外的區域參數。
+ 對於相同帳戶跨區域資料來源，`iamRoleForDataSourceArn`則不需要 。只需要跨帳戶資料來源。
+ 對於 VPC 網域，您必須在呼叫 時將應用程式區域包含在 `SupportedRegions` 參數中`AuthorizeVpcEndpointAccess`。省略 僅`--service-options`授權相同區域存取。
+ 對於 IAM Identity Center 流程，OpenSearch UI 應用程式必須與 IAM Identity Center 執行個體位於相同的區域。
+ 對於具有跨區域網域的 IAM Identity Center 流程，目標網域必須包含在 `IdentityCenterInstanceRegion`中`--identity-center-options`，才能啟用跨區域字符自我檢查。
+ 支援的引擎版本：OpenSearch 1.3 及更高版本。

## 疑難排解
<a name="cross-region-troubleshooting"></a>


| 問題 | Resolution | 
| --- | --- | 
| 應用程式建立失敗，並顯示「無法存取網域」 | 確認網域存在於目標區域中，且已啟用精細存取控制。對於跨帳戶案例，請確認跨帳戶角色具有 es:DescribeDomain許可，且信任政策允許來源帳戶。 | 
| 跨區域的 VPC 網域存取失敗 | 確定 VPC 端點已使用 中包含application.opensearchservice.amazonaws.com的應用程式區域授權給 SupportedRegions。 | 
| IAM 使用者的資料平面存取遭拒 | 檢查目標網域存取政策是否允許 IAM 使用者或角色主體，以及精細存取控制後端角色映射是否授予適當的許可。 | 
| IAM Identity Center 使用者的資料平面存取遭拒 | 確認後端角色映射包含 IAM Identity Center 群組 ID、網域政策允許 IAM Identity Center 應用程式角色，並且IdentityCenterInstanceRegion正確設定為與網域上的 OpenSearch UI 應用程式相同的區域。 | 
| 跨分割區資料來源遭拒 | 不支援跨分割區存取。確保資料來源 ARN 與應用程式位於相同的分割區中。 | 
| 跨區域網域的 IAM Identity Center 身分驗證失敗 | 確認 IdentityCenterInstanceRegion 已設定為啟用 IAM Identity Center 執行個體的正確區域。OpenSearch UI 應用程式也必須位於相同的區域。 | 