

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

# 第 1 步：配置 Amazon Keyspaces 以便与 Apache Cassandra Spark Connector 集成
<a name="spark-tutorial-step1"></a>

在本步骤中，您将确认您的账户的分区程序是否与 Apache Spark Connector 兼容，并设置所需的 IAM 权限。以下最佳实践可帮助您为表配置足够的 read/write 容量。

1. 确认 `Murmur3Partitioner` 分区程序是您账户的默认分区程序。该分区程序与 Spark Cassandra Connector 兼容。有关分区程序以及如何更改分区程序的更多信息，请参阅[使用 Amazon Keyspaces 中的分区程序](working-with-partitioners.md)。

1. 使用 Apache Spark 和接口 VPC 端点为 Amazon Keyspaces 设置 IAM 权限。
   + 分配对用户表的 read/write 访问权限和对系统表的读取权限，如下面列出的 IAM 策略示例所示。
   + 使用 Spark 通过 VPC 端点访问 Amazon Keyspaces 的客户端需要在 system.peers 表中填充您的可用接口 [VPC 端点](https://docs.aws.amazon.com/keyspaces/latest/devguide/vpc-endpoints.html)。

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

1. 请考虑以下最佳实践，为您的 Amazon Keyspaces 表配置足够的读/写吞吐容量，以支持来自 Spark Cassandra Connector 的流量。
   + 开始使用按需容量来帮助您测试场景。
   + 要优化生产环境的表吞吐量成本，请对来自 Connector 的流量使用速率限制器，并将您的表配置为使用具有自动扩缩功能的预配置容量。有关更多信息，请参阅 [使用 Amazon Keyspaces 自动扩缩自动管理吞吐能力](autoscaling.md)。
   + 你可以使用 Cassandra 驱动程序附带的固定速率限制器。[AWS 示例](https://github.com/aws-samples)存储库中有一些[为 Amazon Keyspaces 量身定制的速率限制器](https://github.com/aws-samples/amazon-keyspaces-java-driver-helpers)。
   + 有关容量管理的更多信息，请参阅[在 Amazon Keyspaces 中配置 read/write 容量模式](ReadWriteCapacityMode.md)。