

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

# 使用共用 VPC 中的 VPC 端點設定 Amazon Keyspaces 的跨帳戶存取權
<a name="access.cross-account.sharedVPC"></a>

您可以建立不同的 AWS 帳戶 ，將資源與應用程式分開。例如，您可以為 Amazon Keyspaces 資料表建立一個帳戶、為開發環境中的應用程式建立不同的帳戶，以及為生產環境中的應用程式建立另一個帳戶。本主題會逐步解說在共用 VPC 中使用介面 VPC 端點設定 Amazon Keyspaces 跨帳戶存取所需的組態步驟。

如需如何為 Amazon Keyspaces 設定 VPC 端點的詳細步驟，請參閱 [步驟 3：建立 Amazon Keyspaces 的 VPC 端點](vpc-endpoints-tutorial.create-endpoint.md)。

在此範例中，我們在共用 VPC 中使用下列三個帳戶：
+ `Account A:111111111111` – 此帳戶包含基礎設施，包括 VPC 端點、VPC 子網路和 Amazon Keyspaces 資料表。
+ `Account B:222222222222` – 此帳戶包含在開發環境中的應用程式，需要連線到 中的 Amazon Keyspaces 資料表`Account A:111111111111`。
+ `Account C:333333333333` – 此帳戶包含生產環境中的應用程式，需要連線到 中的 Amazon Keyspaces 資料表`Account A:111111111111`。

![\[圖表顯示使用共用 VPC 之相同 中 AWS 區域 相同組織在 中擁有的三個不同帳戶。\]](http://docs.aws.amazon.com/zh_tw/keyspaces/latest/devguide/images/keyspaces_cross-account_sharedVPC.png)


`Account A:111111111111` 是包含 `Account B:222222222222` 和 `Account C:333333333333` 需要存取之資源 (Amazon Keyspaces 資料表） 的帳戶， `Account A:111111111111`是*信任*帳戶。 `Account B:222222222222`和 `Account C:333333333333`是具有 中需要存取資源 (Amazon Keyspaces 資料表） 之主體的帳戶`Account A:111111111111`，因此 `Account B:222222222222` 和 `Account C:333333333333`是*信任*帳戶。信任帳戶透過共用 IAM 角色，將許可授予信任的帳戶。下列程序概述 中所需的組態步驟`Account A:111111111111`。

**的組態 `Account A:111111111111`**

1. 使用 為子網路 AWS Resource Access Manager 建立資源共用，並與 `Account B:222222222222`和 共用私有子網路`Account C:333333333333`。

   `Account B:222222222222` 和 `Account C:333333333333` 現在可以在已與其共用的子網路中查看和建立資源。

1. 建立採用 技術的 Amazon Keyspaces 私有 VPC 端點 AWS PrivateLink。這會在共用子網路和 Amazon Keyspaces 服務端點的 DNS 項目之間建立多個端點。

1. 建立 Amazon Keyspaces 金鑰空間和資料表。

1. 在 中建立 IAM 角色`Account A:111111111111`，該角色具有 Amazon Keyspaces 資料表的完整存取權、Amazon Keyspaces 系統資料表的讀取存取權，並且能夠描述 Amazon EC2 VPC 資源，如下列政策範例所示。

   ```
   {
       "Version": "2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "CrossAccountAccess",
               "Effect": "Allow",
               "Action": [
                   "ec2:DescribeNetworkInterfaces",
                   "ec2:DescribeVpcEndpoints",
                   "cassandra:*"
               ],
               "Resource": "*"
           }
       ]
   }
   ```

1. 在 中設定 IAM 角色的信任政策，`Account A:111111111111`讓 `Account B:222222222222`和 `Account C:333333333333` 可以擔任該角色做為信任的帳戶。如以下範例所示。

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "AWS": [
             "arn:aws:iam::222222222222:role/Cross-Account-Role-B",
             "arn:aws:iam::333333333333:role/Cross-Account-Role-C"
           ]
         },
         "Action": "sts:AssumeRole",
         "Condition": {}
       }
     ]
   }
   ```

   如需跨帳戶 IAM 政策的詳細資訊，請參閱《IAM 使用者指南》中的[跨帳戶政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic-cross-account.html)。

**`Account B:222222222222` 和 中的組態 `Account C:333333333333`**

1. 在 `Account B:222222222222`和 中`Account C:333333333333`，建立新的角色並連接下列政策，以允許委託人擔任在 中建立的共用角色`Account A:111111111111`。

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

   允許委託人擔任共用角色是使用 AWS Security Token Service (AWS STS) 的 `AssumeRole` API 實作。如需詳細資訊，請參閱《[IAM 使用者指南》中的在您擁有 AWS 帳戶 的另一個 IAM 使用者中提供存取權](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_common-scenarios_aws-accounts.html)。

1. 在 `Account B:222222222222`和 中`Account C:333333333333`，您可以建立使用 SIGV4 身分驗證外掛程式的應用程式，允許應用程式擔任共用角色，`Account A:111111111111`透過共用 VPC 中的 VPC 端點連線到位於 中的 Amazon Keyspaces 資料表。如需 SIGV4 身分驗證外掛程式的詳細資訊，請參閱 [建立 Amazon Keyspaces 的程式設計存取憑證](programmatic.credentials.md)。如需如何設定應用程式以在另一個 AWS 帳戶中擔任角色的詳細資訊，請參閱 *AWS SDKs和工具參考指南中的*[身分驗證和存取](https://docs.aws.amazon.com/sdkref/latest/guide/access.html)。