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



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

我发现我可以将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();

感谢您的帮助。

conf.set("fs.s3a.acl.default", "bucket-owner-full-control");

是您正在设置的正确属性。

因此,core-site.xml中的属性将完全控制权交给bucket所有者。

<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=%sn", 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,那么您必须使用AWS团队的S3连接器,带有"S3://"URL,并使用他们记录的配置选项。他们不支持apache,所以任何一开始带有"fs.s3a"的选项都不会有任何效果。

如Stevenl在回答中所述,对于带有pyspark的EMR,请使用此

sc=spark.sparkContext
hadoop_conf=sc._jsc.hadoopConfiguration()
hadoop_conf.set("fs.s3.canned.acl","BucketOwnerFullControl")

屏蔽ACL描述

BucketOwnerFullControl指定授予bucket的所有者Permission.FullControl.bucket的所有者不一定是与对象的所有者相同。

https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-s3-acls.html

最新更新