amazon-ec2 - 如何在 Spark Streaming EC2 集群应用程序中从 S3 读取输入

标签 amazon-ec2 amazon-s3 apache-spark

我正在尝试让我的 Spark Streaming 应用程序从 S3 目录读取他的输入,但在使用 spark-submit 脚本启动它后,我不断收到此异常:

Exception in thread "main" java.lang.IllegalArgumentException: AWS Access Key ID and Secret Access Key must be specified as the username or password (respectively) of a s3n URL, or by setting the fs.s3n.awsAccessKeyId or fs.s3n.awsSecretAccessKey properties (respectively).
    at org.apache.hadoop.fs.s3.S3Credentials.initialize(S3Credentials.java:66)
    at org.apache.hadoop.fs.s3native.Jets3tNativeFileSystemStore.initialize(Jets3tNativeFileSystemStore.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:82)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:59)
    at org.apache.hadoop.fs.s3native.$Proxy6.initialize(Unknown Source)
    at org.apache.hadoop.fs.s3native.NativeS3FileSystem.initialize(NativeS3FileSystem.java:216)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1386)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1404)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254)
    at org.apache.hadoop.fs.Path.getFileSystem(Path.java:187)
    at org.apache.spark.streaming.StreamingContext.checkpoint(StreamingContext.scala:195)
    at MainClass$.main(MainClass.scala:1190)
    at MainClass.main(MainClass.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:292)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:55)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

我通过这里建议的代码块设置这些变量 http://spark.apache.org/docs/latest/ec2-scripts.html (页面底部):
val ssc = new org.apache.spark.streaming.StreamingContext(
  conf,
  Seconds(60))
ssc.sparkContext.hadoopConfiguration.set("fs.s3n.awsAccessKeyId",args(2))
ssc.sparkContext.hadoopConfiguration.set("fs.s3n.awsSecretAccessKey",args(3))

args(2) 和 args(3) 当然是我的 AWS 访问 key ID 和 secret 访问 key 。

为什么它一直说他们没有设置?

编辑:我也尝试过这种方式,但我得到了同样的异常(exception):
val lines = ssc.textFileStream("s3n://"+ args(2) +":"+ args(3) + "@<mybucket>/path/")

最佳答案

奇怪的。也尝试做一个.setsparkContext .尝试在启动应用程序之前导出环境变量:

export AWS_ACCESS_KEY_ID=<your access>
export AWS_SECRET_ACCESS_KEY=<your secret>

^^这就是我们的做法。

更新:根据@tribbloid,上述内容在 1.3.0 中出现了问题,现在您必须使用 hdfs-site.xml 进行多年的工作,或者您可以这样做(这在 spark-shell 中有效):
val hadoopConf = sc.hadoopConfiguration;
hadoopConf.set("fs.s3.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")
hadoopConf.set("fs.s3.awsAccessKeyId", myAccessKey)
hadoopConf.set("fs.s3.awsSecretAccessKey", mySecretKey)

关于amazon-ec2 - 如何在 Spark Streaming EC2 集群应用程序中从 S3 读取输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52528041/

相关文章:

amazon-web-services - 创建堆栈后自动上传文件到S3存储桶

scala - Apache Spark:将结果保存到数据库

python - Spark 缓存和取消持久化订单

Python virtualenv 没有名为 django 的模块

ssh - 从ansible ping ec2 实例

Python configparser 从 S3 读取配置而不下载

java - 线程 “main”中的ExException java.lang.IllegalArgumentException:/home不能是目录

javascript - 使用node.js中的AWS ec2.describeInstances从嵌套对象中提取数据

java - AWS 自定义 CloudWatch 指标 - 按 Auto-Scaling 组聚合

amazon-s3 - S3 写后读的最终一致性