使用 3 种方法在 Spark 程序上设置 AWS 凭证,其中 None 有效

Setting AWS credentials on Spark program using 3 methods, None of them works

我正在启动一个使用 S3 作为仓库的 Spark 配置单元服务器集群。我已经使用 3 种方法冗余设置了我的 AWS 凭证,即:

  1. hdfs-site.xml 下 $SPARK_HOME/conf:

<property>
  <name>fs.s3.awsAccessKeyId</name>
  <value>****</value>
</property>

<property>
  <name>fs.s3.awsSecretAccessKey</name>
  <value>****</value>
</property>

  1. 通过在 start-hivethrift 参数中使用 spark.executor.extraJavaOptions 设置执行者的系统 属性:

    --conf "spark.executor.extraJavaOptions=-Dfs.s3.awsAccessKeyId=**** -Dfs.s3.awsSecretAccessKey=****" \

  2. 在start-hivethrift之前设置环境变量。

启动脚本如下所示:

AWS_ACCESS_KEY_ID=**** \
AWS_SECRET_ACCESS_KEY=**** \
$SPARK_HOME/sbin/start-thriftserver.sh \
--conf "spark.executor.extraJavaOptions=-Dfs.s3.awsAccessKeyId=**** -Dfs.s3.awsSecretAccessKey=****" \
--hiveconf hive.metastore.warehouse.dir=s3n://testdata \

但是当我 运行 任何创建 table 查询时,我仍然得到:

Error: org.apache.spark.sql.execution.QueryExecutionException: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message: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).) (state=,code=0)

这是怎么回事?为什么其中 none 像文档中那样工作?

糟糕,我的 hdfs-site.xml 有问题。我应该添加 S3 支持的所有可能的模式名称:

<configuration>

<property>
  <name>fs.s3.awsAccessKeyId</name>
  <value>****</value>
</property>

<property>
  <name>fs.s3.awsSecretAccessKey</name>
  <value>****</value>
</property>

<property>
  <name>fs.s3n.awsAccessKeyId</name>
  <value>****</value>
</property>

<property>
  <name>fs.s3n.awsSecretAccessKey</name>
  <value>****</value>
</property>

<property>
  <name>fs.s3a.awsAccessKeyId</name>
  <value>****</value>
</property>

<property>
  <name>fs.s3a.awsSecretAccessKey</name>
  <value>****</value>
</property>

</configuration>

现在似乎没有问题了。有点不方便,但我很高兴它现在可以用了。