使用 Apache Spark 运行处理作业 - 亚马逊 SageMaker AI
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

使用 Apache Spark 运行处理作业

Apache Spark 是用于大规模数据处理的统一分析引擎。Amazon SageMaker AI 提供了预构建的 Docker 映像,包括 Apache Spark 和运行分布式数据处理作业所需的其他依赖项。下面举例说明如何使用 Apache Spark 运行 Amazon SageMaker Processing 作业。

通过 Amazon SageMaker Python SDK,您可以使用 Spark 框架轻松应用数据转换并提取特征(特征工程)。有关使用 SageMaker Python SDK 运行 Spark 处理作业的信息,请参阅 Amazon SageMaker Python SDK 中的使用 Spark 进行数据处理

包含 Spark 映像的源代码和 Dockerfile 的代码存储库可在 GitHub 上找到。

您可以使用 sagemaker.spark.PySparkProcessorsagemaker.spark.SparkJarProcessor 类,在处理作业中运行 Spark 应用程序。请注意,您可以将 MaxRuntimeInSeconds 设置为最大运行时限制,即 5 天。关于执行时间和使用的实例数量,简单的 Spark 工作负载会注意到实例数量与完成时间之间的近线性关系。

以下代码示例演示了如何运行调用 PySpark 脚本 preprocess.py 的处理作业。

from sagemaker.spark.processing import PySparkProcessor spark_processor = PySparkProcessor( base_job_name="spark-preprocessor", framework_version="2.4", role=role, instance_count=2, instance_type="ml.m5.xlarge", max_runtime_in_seconds=1200, ) spark_processor.run( submit_app="preprocess.py", arguments=['s3_input_bucket', bucket, 's3_input_key_prefix', input_prefix, 's3_output_bucket', bucket, 's3_output_key_prefix', output_prefix] )

要深入研究,请参阅“使用 Apache Spark 和 SageMaker Processing 进行分布式数据处理”示例笔记本

如果您没有使用 Amazon SageMaker AI Python SDK 以及其中一个处理器类来检索预构建的映像,您可以自己检索这些映像。SageMaker 预构建的 Docker 映像存储在 Amazon Elastic Container Registry (Amazon ECR) 中。有关可用的预构建 Docker 映像的完整列表,请参阅可用的映像文档。

要了解有关结合使用 SageMaker Python SDK 和处理容器的更多信息,请参阅 Amazon SageMaker AI Python SDK