如何在AWS EMR上设置Hadoop fs.s3a.acl.default?

问题描述 投票:0回答:2

我有一个在AWS EMR上运行的map-reduce应用程序,该应用程序将一些输出写入不同的(aws帐户)s3存储桶。我具有权限设置,并且该作业可以写入外部存储桶,但是所有者仍然是运行Hadoop作业的帐户的root。我想将其更改为拥有该存储桶的外部帐户。

我发现我可以将fs.s3a.acl.default设置为bucket-owner-full-control,但这似乎不起作用。这就是我在做什么:

conf.set("fs.s3a.acl.default", "bucket-owner-full-control");
FileSystem fileSystem = FileSystem.get(URI.create(s3Path), conf);
FSDataOutputStream fsDataOutputStream = fileSystem.create(new Path(filePath));
PrintWriter writer  = new PrintWriter(fsDataOutputStream);
writer.write(contentAsString);
writer.close();
fsDataOutputStream.close();

感谢您的任何帮助。

scala apache-spark hadoop amazon-s3 amazon-emr
2个回答
1
投票
conf.set("fs.s3a.acl.default", "bucket-owner-full-control");

是您要设置的正确属性。

因此,core-site.xml中的属性可以完全控制存储桶所有者。

<property>
  <name>fs.s3a.acl.default</name>
  <description>Set a canned ACL for newly created and copied objects. Value may be private,
     public-read, public-read-write, authenticated-read, log-delivery-write,
     bucket-owner-read, or bucket-owner-full-control.</description>
</property>

BucketOwnerFullControl] >>

    Specifies that the owner of the bucket is granted Permission.FullControl. The owner of the bucket is not necessarily the same as the owner of the object.

我建议也将fs.s3.canned.acl设置为值BucketOwnerFullControl

对于调试,您可以使用下面的代码片段了解实际传递的参数。

for (Entry<String, String> entry: conf) {
      System.out.printf("%s=%s\n", entry.getKey(), entry.getValue());
    }

出于测试目的,请使用命令行执行此命令

aws s3 cp s3://bucket/source/dummyfile.txt s3://bucket/target/dummyfile.txt --sse --acl bucket-owner-full-control

如果这有效,那么通过api也可以。

Spark的奖励积分,对Spark Scala用户有用:

用于Spark访问s3文件系统并设置适当的配置,如下面的示例...

val hadoopConf = spark.sparkContext.hadoopConfiguration
    hadoopConf.set("fs.s3a.fast.upload","true")
    hadoopConf.set("mapreduce.fileoutputcommitter.algorithm.version","2")
    hadoopConf.set("fs.s3a.server-side-encryption-algorithm", "AES256")
    hadoopConf.set("fs.s3a.canned.acl","BucketOwnerFullControl")
    hadoopConf.set("fs.s3a.acl.default","BucketOwnerFullControl")

[如果您使用的是EMR,则必须使用带有“ s3://” URL的AWS团队的S3连接器,并使用其记录的配置选项。他们不支持apache,所以任何开头带有“ fs.s3a”的选项都不会有任何效果。


0
投票

[如果您使用的是EMR,则必须使用带有“ s3://” URL的AWS团队的S3连接器,并使用其记录的配置选项。他们不支持apache,所以任何开头带有“ fs.s3a”的选项都不会有任何效果。

© www.soinside.com 2019 - 2024. All rights reserved.