【问题标题】:Issue while connecting Amazon s3 using pySpark使用 pySpark 连接 Amazon s3 时出现问题
【发布时间】:2016-02-23 01:38:21
【问题描述】:

我使用的是 Spark 1.6 版本的本地模式。以下是我的代码:

第一次尝试:

airline = sc.textFile("s3n://mortar-example-data/airline-data")
airline.take(2)

第二次尝试:

airline = sc.textFile("s3n://myid:mykey@mortar-example-data/airline-data")
airline.take(2)

上面的代码给我以下错误:

Py4JJavaError: An error occurred while calling o17.partitions.
: java.io.IOException: No FileSystem for scheme: s3n
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2584)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2591)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:91)

不确定这里缺少什么来连接到 S3。如果有人能指出我就太好了

【问题讨论】:

标签: python amazon-web-services amazon-s3 pyspark


【解决方案1】:

@约翰

以下是我的解决方案

bucket = "your bucket"

# Prod App Key
prefix = "Your path to the file"
filename = "s3n://{}/{}".format(bucket, prefix)
sc._jsc.hadoopConfiguration().set("fs.s3n.awsAccessKeyId", "YourAccessKey")
sc._jsc.hadoopConfiguration().set("fs.s3n.awsSecretAccessKey", "YourSecret key") 

rdd = sc.hadoopFile(filename,
                    'org.apache.hadoop.mapred.TextInputFormat',
                    'org.apache.hadoop.io.Text',
                    'org.apache.hadoop.io.LongWritable',
                    )
rdd.count()

上面的代码对我有用...祝你好运。

【讨论】:

    猜你喜欢
    • 2013-10-29
    • 2021-12-30
    • 2021-06-20
    • 2020-08-24
    • 2011-11-15
    • 2011-06-09
    • 1970-01-01
    • 2021-11-13
    • 2020-11-13
    相关资源
    最近更新 更多