

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 VPC 端点配置对 Amazon Keyspaces 的跨账户访问
<a name="access.cross-account"></a>

您可以单独创建和使用 AWS 账户 以隔离资源并用于不同的环境，例如开发和生产。本主题介绍了如何在 Amazon Virtual Private Cloud中使用接口 VPC 端点对 Amazon Keyspaces 进行跨账户访问。有关 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 端点的更多信息，请参阅[将 Amazon Keyspaces 与接口 VPC 端点结合使用](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`：此账户包含开发环境中的一个应用程序，该应用程序需要连接到`Account A:111111111111` 中的 Amazon Keyspaces 表。
+ `Account C:333333333333`：此账户包含生产环境中的一个应用程序，该应用程序需要连接到`Account A:111111111111` 中的 Amazon Keyspaces 表。

![\[示意图：显示了同一组织在同一 AWS 区域 拥有的三个使用共享 VPC 的不同账户。\]](http://docs.aws.amazon.com/zh_cn/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 VP EC2 C 资源，如以下策略示例所示。

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

1. 在中为 IAM 角色配置信任策略`Account B:222222222222`，`Account A:111111111111`以便`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 A:111111111111`、`Account B:222222222222` 和`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 倍。

![\[示意图：显示了同一组织在同一 AWS 区域 拥有的三个没有共享 VPC 的不同账户。\]](http://docs.aws.amazon.com/zh_cn/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. 在中创建一个 IAM 角色`Account A:111111111111`，该角色具有对 Amazon Keyspaces 表的完全访问权限和对 Amazon Keyspaces 系统表的读取权限。

   ```
   {
      "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 C:333333333333`扮演角色的角色`Account A`使用 VPC 终端节点。这些权限对它们所连接的 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)。