权限被拒绝从安装在 EMR 上的 Zeppelin 访问 S3 文件

Permission Denied Access S3 file from Zeppelin installed on EMR

在 EMR 上启动集群

设置:

user: AdministratorPolicy (access all)
keypairs: yes
sandbox: Zeppelin
Application: Spark 1.5.0, Hadoop 2.6.0
IAM: defaultEMRRole
Bootstrap Action: no
IAM users: all
steps: no

然后我在我的本地机器上得到 Zeppelin UI,地址为:

instance-public-dns:8890

成功

创建一个新笔记本: 运行

sc

return

res42: org.apache.spark.SparkContext =org.apache.spark.SparkContext@523b1d4c

然后我尝试从 S3 将数据加载到 spark

sc.hadoopConfiguration.set("fs.s3n.awsAccessKeyId","++")
sc.hadoopConfiguration.set("fs.s3n.awsSecretAccessKey","++")
var textFile = sc.textFile("s3n://<instance>/<bucket-name>/pagecounts-20081001-070000")
textFile.first()

然后报错

com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: FD784A9D96A0D54A), S3 Extended Request ID: oOgHwbN8tW2TIxpgagPIZ+NpsTmymzh6wiJ2a6zYhD8XeiH3pHVKpTOeYXOS0dzgBGqKsjr+ls8=
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1182)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:770)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:489)

您应该不需要设置 "fs.s3n.awsAccessKeyId" 或 "fs.s3n.awsSecretAccessKey"。你能试着不设置那些然后只使用 "s3" 而不是 "s3n":

var textFile = sc.textFile("s3:////pagecounts-20081001-070000") textFile.first()