

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

# 将 Amazon Keyspaces 与接口 VPC 端点结合使用
<a name="vpc-endpoints"></a>

接口 VPC 端点可以在 Amazon VPC 中运行的虚拟私有云 (VPC) 与 Amazon Keyspaces 之间实现私有通信。接口 VPC 终端节点由提供支持 AWS PrivateLink，这是一项支持 VPCs 和 AWS 服务之间私有通信的 AWS 服务。

AWS PrivateLink 通过在您的 VPC 中使用带有私有 IP 地址的 elastic network interface 来实现这一点，这样网络流量就不会离开亚马逊网络。接口 VPC 端点不需要互联网网关、NAT 设备、VPN 连接或 Direct Connect 连接。有关更多信息，请参阅 [Amazon Virtual Private Cloud](https://docs.aws.amazon.com/vpc/latest/userguide/) 和 [接口 VPC 端点 (AWS PrivateLink)](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html)。

**Topics**
+ [将接口 VPC 端点用于 Amazon Keyspaces](#using-interface-vpc-endpoints)
+ [使用接口 VPC 端点信息填充 `system.peers` 表条目](#system_peers)
+ [控制 Amazon Keyspaces 对接口 VPC 端点的访问](#interface-vpc-endpoints-policies)
+ [可用性](#availability)
+ [VPC 终端节点策略和 Amazon Keyspaces point-in-time 恢复 (PITR)](#VPC_PITR_restore)
+ [常见错误和警告](#vpc_troubleshooting)

## 将接口 VPC 端点用于 Amazon Keyspaces
<a name="using-interface-vpc-endpoints"></a>

您可以创建接口 VPC 端点，这样 Amazon Keyspaces 和 Amazon VPC 资源之间的流量就会通过接口 VPC 端点开始流动。要开始使用，请按照步骤[创建接口端点](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html#create-interface-endpoint)。接下来，编辑与您在上一步中创建的终端节点关联的安全组，并为端口 9142 配置入站规则。有关详细信息，请参阅[添加、删除和更新规则](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#AddRemoveRules)。

有关通过 VPC 终端节点配置与 Amazon Keyspaces 的连接的 step-by-step教程，请参阅。[教程：使用接口 VPC 终端节点连接到 Amazon Keyspaces](vpc-endpoints-tutorial.md)要了解如何为与 VPC 中 AWS 账户 不同应用程序分开的 Amazon Keyspaces 资源配置跨账户访问权限，请参阅。[使用 VPC 端点配置对 Amazon Keyspaces 的跨账户访问](access.cross-account.md)

## 使用接口 VPC 端点信息填充 `system.peers` 表条目
<a name="system_peers"></a>

Apache Cassandra 驱动程序使用该 `system.peers` 表来查询有关集群的节点信息。Cassandra 驱动程序使用节点信息对连接进行负载均衡并重试操作。Amazon Keyspaces 会自动为通过公共端点连接的客户端填充 `system.peers` 表中的九个条目。

为了向通过接口 VPC 端点连接的客户端提供类似的功能，Amazon Keyspaces 会在您账户的 `system.peers` 表格中填充一个条目，用于显示 VPC 端点可用的每个可用区。要在 `system.peers` 表中查找和存储可用的接口 VPC 端点，Amazon Keyspaces 要求您向用于连接到 Amazon Keyspaces 的 IAM 实体授予访问权限，以查询您的 VPC 的端点和网络接口信息。

**重要**  
在`system.peers`表格中填充您的可用接口 VPC 终端节点可以改善负载平衡并增加 read/write 吞吐量。建议使用接口 VPC 端点访问 Amazon Keyspaces 的所有客户端都这样做，Apache Spark 也需要这样做。

要向用于连接 Amazon Keyspaces 的 IAM 实体授予权限以查找必要的接口 VPC 端点信息，可以更新现有的 IAM 角色或用户策略，或创建新的 IAM 策略，如以下示例所示。

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

**注意**  
托管式策略 `AmazonKeyspacesReadOnlyAccess_v2` 和 `AmazonKeyspacesFullAccess` 包含允许 Amazon Keyspaces 访问 Amazon EC2 实例以读取可用接口 VPC 端点信息所需的权限。

要确认策略设置是否正确，请查询 `system.peers` 表以查看网络信息。如果该 `system.peers` 表为空，则可能表示策略未成功配置，或者您已超出 `DescribeNetworkInterfaces` 和 `DescribeVPCEndpoints` API 操作的请求速率限额。`DescribeVPCEndpoints` 属于 `Describe*` 类别，被视为*非变异操作*。`DescribeNetworkInterfaces` 属于*未过滤和未分页的非变异操作*的子集，并且适用不同的限额。有关更多信息，请参阅 Amazon EC2 API 参考中的[请求令牌桶大小和重新填充率](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/throttling.html#throttling-limits-rate-based)。

如果您看到一张空表，请在几分钟后重试，以排除请求速率限额问题。要验证您是否正确配置了 VPC 端点，请参阅[我的 VPC 端点连接无法正常工作](troubleshooting.connecting.md#troubleshooting.connection.vpce)。如果您的查询返回表中的结果，说明您的策略配置正确。



## 控制 Amazon Keyspaces 对接口 VPC 端点的访问
<a name="interface-vpc-endpoints-policies"></a>

VPC 端点策略使您能够通过两种方式控制对资源的访问：
+ **IAM 策略** – 您可以控制允许通过特定 VPC 端点访问 Amazon Keyspaces 的请求、用户或组。您可以通过在附加到 IAM 用户、组或角色的策略中使用[条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)来完成此操作。
+ **VPC 策略** – 您可以通过向 VPC 端点附加策略来控制哪些端点可以访问您的 Amazon Keyspaces 资源。要限制仅允许通过特定 VPC 终端节点的流量来访问特定键空间或表，请编辑限制资源访问的现有 IAM 策略并添加该 VPC 终端节点。



下面是访问 Amazon Keyspaces 资源的端点策略示例。
+ **IAM 策略示例：限制对特定 Amazon Keyspaces 表的所有访问，除非流量来自指定的 VPC 端点** – 此示例策略可以附加到 IAM 用户、角色或组。它限制对指定 Amazon Keyspaces 表的访问，除非传入流量来自指定的 VPC 端点。

  ```
  {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
        {
           "Sid": "UserOrRolePolicyToDenyAccess",
           "Action": "cassandra:*",
           "Effect": "Deny",
           "Resource": [
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
             ],
           "Condition": { "StringNotEquals" : { "aws:sourceVpce": "vpce-abc123" } }
        }
     ]
  }
  ```
**注意**  
要限制对特定表的访问，还必须包括对系统表的访问权限。系统表为只读。
+ **VPC 策略示例：只读访问** – 此示例策略可以附加到 VPC 端点。（有关更多信息，请参阅[控制对 Amazon VPC 资源的访问](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints-access.html#vpc-endpoint-policies)）。它限制通过所连接的 VPC 端点对 Amazon Keyspaces 资源进行只读访问的操作。

  ```
  {
    "Version": "2012-10-17",		 	 	 
    "Statement": [
      {
        "Sid": "ReadOnly",
        "Principal": "*",
        "Action": [
          "cassandra:Select"
        ],
        "Effect": "Allow",
        "Resource": "*"
      }
    ]
  }
  ```
+ **VPC 策略示例：限制对特定 Amazon Keyspaces 表的访问** – 此示例策略可以附加到 VPC 端点。它限制通过所附加到的 VPC 端点访问特定表。

  ```
  {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
          {
              "Sid": "RestrictAccessToTable",
              "Principal": "*",
              "Action": "cassandra:*",
              "Effect": "Allow",
              "Resource": [
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
             ]
          }
     ]
  }
  ```
**注意**  
要限制对特定表的访问，还必须包括对系统表的访问权限。系统表为只读。

## 可用性
<a name="availability"></a>

Amazon Keyspaces 支持在所有提供服务 AWS 区域 的地方使用接口 VPC 终端节点。有关更多信息，请参阅 [Amazon Keyspaces 的服务端点](programmatic.endpoints.md)。

## VPC 终端节点策略和 Amazon Keyspaces point-in-time 恢复 (PITR)
<a name="VPC_PITR_restore"></a>

如果您使用带有[条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)的 IAM 策略来限制传入流量，则表恢复操作可能会失败。例如，如果您使用 `aws:SourceVpce` 条件键将源流量限制到特定 VPC 端点，则表恢复操作将失败。要允许 Amazon Keyspaces 代表您的主体执行恢复操作，您必须在 IAM 策略中添加 `aws:ViaAWSService` 条件键。当任何 AWS 服务使用委托人的证书发出请求时，`aws:ViaAWSService`条件密钥允许访问。有关更多信息，请参阅《IAM 用户指南》中的 [IAM JSON 策略元素：条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)**。下面是一个示例策略。

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Sid":"CassandraAccessForVPCE",
         "Effect":"Allow",
         "Action":"cassandra:*",
         "Resource":"*",
         "Condition":{
            "Bool":{
               "aws:ViaAWSService":"false"
            },
            "StringEquals":{
               "aws:SourceVpce":[
                  "vpce-12345678901234567"
               ]
            }
         }
      },
      {
         "Sid":"CassandraAccessForAwsService",
         "Effect":"Allow",
         "Action":"cassandra:*",
         "Resource":"*",
         "Condition":{
            "Bool":{
               "aws:ViaAWSService":"true"
            }
         }
      }
   ]
}
```

## 常见错误和警告
<a name="vpc_troubleshooting"></a>

**如果您使用的是 Amazon Virtual Private Cloud 并连接到 Amazon Keyspaces，可能会看到以下警告。**

```
Control node cassandra.us-east-1.amazonaws.com/1.111.111.111:9142 has an entry for itself in system.peers: this entry will be ignored. This is likely due to a misconfiguration; 
please verify your rpc_address configuration in cassandra.yaml on all nodes in your cluster.
```

之所以出现此警告，是因为 `system.peers` 表包含 Amazon Keyspaces 有权查看的所有 Amazon VPC 端点的条目，包括您通过其连接的 Amazon VPC 端点。您可以放心地忽略这一警告。

有关其他错误，请参阅[我的 VPC 端点连接无法正常工作](troubleshooting.connecting.md#troubleshooting.connection.vpce)。