首页 > 解决方案 > Amazon EMR S3A 支持

问题描述

它说,我根据 Amazon 的文档 ( https://aws.amazon.com/premiumsupport/knowledge-center/emr-file-system-s3/ )使用 Spark 开发了 Amazon EMR Amazon EMR does not currently support use of the Apache Hadoop S3A file system, The s3a:// URI is not compatible with Amazon EMR
但是,我可以毫无问题地使用“s3a://”在火花作业中进行读写。(注意:我使用"com.amazonaws" % "aws-java-sdk-s3" % "1.11.286"的是 EMR 版本emr-5.11.0)。我进行了一些搜索,但仍然对目前建议将哪个文件系统与 EMR 一起使用感到困惑。
任何帮助,将不胜感激。

标签: amazon-web-servicesapache-sparkamazon-s3amazon-emr

解决方案


编辑:忘了说明这一点,但这是使用 Spark 版本 2.3.0 构建的。

AWS EMR 具有三个可在 Spark s3a、s3e 和 s3 中使用的策略。s3a 和 s3e 是用于连接到可在 AWS 内外使用的环境的相对较旧的策略。而 s3 是专门为连接到 s3 的 AWS EMR 构建的策略。通过测试,我发现使用 s3 策略读取和写入速度更快,并且与其他策略不同,您不需要通过用户/密码/密钥/库。唯一需要的是,当 spark shell 处于活动状态时,VPC 中的用户或其他用户可以访问存储桶和 spark。以下是使用 S3 进行读写的方法:

spark-shell
///In this case I am reading a csv from a bucket called myBucket into the environment
val inputDF = spark.read.format("csv").option("header","true").load("s3://myBucket/fooBar.csv")
///I am then writing that file back out using the s3 policy back to the environment
inputDF.write.format("csv").save("s3://myBucket/ODS/")

从 Spark 读取负载时,您将看到的最大问题是分区,这意味着在读取之前 Spark 决定对对象元素进行的任何分区是它将写入多少部分文件。如果您正在寻找加快读写速度,您可能需要考虑实施重新分区策略。

导入 org.apache.spark.util.SizeEstimator

val inputDF2 : Long = SizeEstimator.estimate(inputDF.rdd)
//find its appropiate number of partitions
val numPartitions : Long = (inputDF2/134217728) + 1
//write it out with that many partitions
val outputDF = inputDF.repartition(numPartitions.toInt)

推荐阅读