PySpark:AWS s3n 正在工作,但 s3a 没有

Posted

技术标签:

【中文标题】PySpark:AWS s3n 正在工作,但 s3a 没有【英文标题】:PySpark: AWS s3n is working but s3a doesn't 【发布时间】:2016-11-20 06:14:18 【问题描述】:

我一直在尝试使用本地计算机上的 Spark 访问 Amazon s3 上的数据。我可以使用 s3n 访问数据,但不能使用 s3a,以下是配置

Spark :- 使用 hadoop 2.7 预构建的 2.0.1

spark-defauts.conf parameters :- 
spark.jars.packages             com.amazonaws:aws-java-sdk:1.7.4,org.apache.hadoop:hadoop-aws:2.7.1
spark.hadoop.fs.s3a.impl        org.apache.hadoop.fs.s3a.S3AFileSystem
spark.hadoop.fs.s3a.access.key  accesskey
spark.hadoop.fs.s3a.secret.key  secretkey
spark.hadoop.fs.s3a.fast.upload true

出现错误:-

Py4JJavaError: An error occurred while calling o235.partitions.
: com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 400, AWS Service: Amazon S3, AWS Request ID: , AWS Error Code: null, AWS Error Message: Bad Request, S3 Extended Request ID: 
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:798)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:421)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:232)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3528)
    at com.amazonaws.services.s3.AmazonS3Client.headBucket(AmazonS3Client.java:1031)
    at com.amazonaws.services.s3.AmazonS3Client.doesBucketExist(AmazonS3Client.java:994)
    at org.apache.hadoop.fs.s3a.S3AFileSystem.initialize(S3AFileSystem.java:297)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2669)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:94)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2703)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2685)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:373)
    at org.apache.hadoop.fs.Path.getFileSystem(Path.java:295)
    at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:258)
    at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:229)
    at org.apache.hadoop.mapred.FileInputFormat.getSplits(FileInputFormat.java:315)
    at org.apache.spark.rdd.HadoopRDD.getPartitions(HadoopRDD.scala:199)
    at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:248)
    at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:246)
    at scala.Option.getOrElse(Option.scala:121)
    at org.apache.spark.rdd.RDD.partitions(RDD.scala:246)
    at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:35)
    at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:248)
    at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:246)
    at scala.Option.getOrElse(Option.scala:121)
    at org.apache.spark.rdd.RDD.partitions(RDD.scala:246)
    at org.apache.spark.api.java.JavaRDDLike$class.partitions(JavaRDDLike.scala:60)
    at org.apache.spark.api.java.AbstractJavaRDDLike.partitions(JavaRDDLike.scala:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:237)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:745)

我该如何解决这个错误?

【问题讨论】:

可能相关:Spark read file from S3 using sc.textFile ("s3n://…) 和 Accessing Data Stored in Amazon S3 through Spark 【参考方案1】:

您可能正在尝试使用 Seoul、Frankfurt 或 V4-auth-only 区域中的其他存储桶,但仍将端点设置为默认的 us-east。

将 fs.s3a.endpoint 的值更改为适当的值。请参阅“使用不同区域的存储桶”

https://github.com/apache/hadoop/blob/trunk/hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/index.md

ps:在 hadoop 2.7 中快速上传要非常小心;除非您调整队列长度,否则容易出现 OOM。为 Hadoop 2.8 完全重写,默认缓冲为 HDD。

【讨论】:

以上是关于PySpark:AWS s3n 正在工作,但 s3a 没有的主要内容,如果未能解决你的问题,请参考以下文章

从 pyspark 访问 S3 存储桶中的文件

如何从本地 Hadoop 2.6 安装访问 S3/S3n?

使用 pySpark 连接 Amazon s3 时出现问题

将 AWS S3 连接到 Databricks PySpark

从aws glue pyspark作业中的s3加载JSON

S3N 和 S3A distcp 在 Hadoop 2.6.0 中不起作用