

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

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

您可以建立並使用個別 AWS 帳戶 來隔離資源，並在不同的環境中使用，例如開發和生產。本主題使用 中的介面 VPC 端點，逐步引導您存取 Amazon Keyspaces 的跨帳戶 Amazon Virtual Private Cloud。如需 IAM 跨帳戶存取組態的詳細資訊，請參閱《IAM 使用者指南》中的[使用個別開發和生產帳戶的範例案例](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_common-scenarios_aws-accounts.html#id_roles_common-scenarios_aws-accounts-example)。

如需 Amazon Keyspaces 和私有 VPC 端點的詳細資訊，請參閱 [搭配界面 VPC 端點使用 Amazon Keyspaces](vpc-endpoints.md)。

**Topics**
+ [在共用 VPC 中設定跨帳戶存取](access.cross-account.sharedVPC.md)
+ [設定沒有共用 VPC 的跨帳戶存取](access.cross-account.noVPC.setup.md)

# 使用共用 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)。

# 設定沒有共用 VPC 的 Amazon Keyspaces 跨帳戶存取權
<a name="access.cross-account.noVPC.setup"></a>

如果 Amazon Keyspaces 資料表和私有 VPC 端點為不同帳戶所擁有，但未共用 VPC，則應用程式仍然可以使用 VPC 端點來連接跨帳戶。由於帳戶不會共用 VPC 端點，`Account B:222222222222`因此 `Account A:111111111111`、 和 `Account C:333333333333`需要自己的 VPC 端點。對於 Cassandra 用戶端驅動程式，Amazon Keyspaces 會顯示為單一節點，而不是多節點叢集。連線時，用戶端驅動程式會到達 DNS 伺服器，傳回帳戶 VPC 中其中一個可用的端點。

您也可以使用公有端點或在每個帳戶中部署私有 VPC 端點，存取不同帳戶的 Amazon Keyspaces 資料表，而無需共用 VPC 端點。不使用共用 VPC 時，每個帳戶都需要自己的 VPC 端點。在此範例中，`Account A:111111111111`、 `Account B:222222222222`和 `Account C:333333333333`需要自己的 VPC 端點才能存取 中的資料表`Account A:111111111111`。在此組態中使用 VPC 端點時，Amazon Keyspaces 會顯示為 Cassandra 用戶端驅動程式的單一節點叢集，而非多節點叢集。連線時，用戶端驅動程式會到達 DNS 伺服器，傳回帳戶 VPC 中其中一個可用的端點。但用戶端驅動程式無法存取`system.peers`資料表來探索其他端點。由於可用的主機較少，驅動程式的連線較少。若要調整此值，請將驅動程式的連線集區設定增加 3 倍。

![\[圖表顯示沒有共用 VPC 的相同組織在 AWS 區域 中擁有的三個不同帳戶。\]](http://docs.aws.amazon.com/zh_tw/keyspaces/latest/devguide/images/keyspaces_cross-account_noVPC.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. 在 中建立 Amazon Keyspaces 金鑰空間和資料表`Account A:111111111111`。

1. 在 中建立`Account A:111111111111`具有 Amazon Keyspaces 資料表完整存取權和 Amazon Keyspaces 系統資料表讀取存取權的 IAM 角色。

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[
         {
            "Effect":"Allow",
            "Action":[
               "cassandra:Select",
               "cassandra:Modify"
            ],
            "Resource":[
               "arn:aws:cassandra:us-east-1:111111111111:/keyspace/mykeyspace/table/mytable",
               "arn:aws:cassandra:us-east-1:111111111111:/keyspace/system*"
            ]
         }
      ]
   }
   ```

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)。

1. 在 中設定 VPC 端點，`Account A:111111111111`並將許可連接到允許來自 `Account B:222222222222`和 的角色`Account A`使用 VPC 端點`Account C:333333333333`擔任 中角色的端點。這些許可對其連接的 VPC 端點有效。如需 VPC 端點政策的詳細資訊，請參閱 [控制對 Amazon Keyspaces 介面 VPC 端點的存取](vpc-endpoints.md#interface-vpc-endpoints-policies)。

   ```
   {{
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "AllowAccessfromSpecificIAMroles",
         "Effect": "Allow",
         "Action": "cassandra:*",
         "Resource": "*",
         "Principal": "*",
         "Condition": {
           "ArnEquals": {
             "aws:PrincipalArn": [
               "arn:aws:iam::222222222222:role/Cross-Account-Role-B",
               "arn:aws:iam::333333333333:role/Cross-Account-Role-C"
             ]
           }
         }
       }
     ]
   }
   ```

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

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

   ```
   {
       "Version": "2012-10-17",		 	 	 
       "Statement": {
               "Effect": "Allow",
               "Action": "sts:AssumeRole",
               "Resource": "arn:aws:iam::111111111111:role/keyspaces_access"
           }
   }
   ```

   允許委託人擔任共用角色是使用 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 身分驗證外掛程式的應用程式，允許應用程式擔任共用角色以連線到位於 中的 Amazon Keyspaces 資料表`Account A:111111111111`。如需 SIGV4 身分驗證外掛程式的詳細資訊，請參閱 [建立 Amazon Keyspaces 的程式設計存取憑證](programmatic.credentials.md)。如需如何設定應用程式以在另一個 AWS 帳戶中擔任角色的詳細資訊，請參閱 *AWS SDKs和工具參考指南中的*[身分驗證和存取](https://docs.aws.amazon.com/sdkref/latest/guide/access.html)。