如何为org.apache.parquet.avro.AvroParquetReader配置S3访问? [英] How do I configure S3 access for org.apache.parquet.avro.AvroParquetReader?

查看:63
本文介绍了如何为org.apache.parquet.avro.AvroParquetReader配置S3访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个问题上挣扎了一段时间,想分享我的解决方案。AvroParquetReader是一个很好的阅读Parquet的工具,但它对S3访问的默认设置很弱:

java.io.InterruptedIOException: doesBucketExist on MY_BUCKET: com.amazonaws.AmazonClientException: No AWS Credentials provided by BasicAWSCredentialsProvider EnvironmentVariableCredentialsProvider SharedInstanceProfileCredentialsProvider : com.amazonaws.AmazonClientException: Unable to load credentials from service endpoint

我想使用类似于com.amazonaws.auth.profile.ProfileCredentialsProvider,使用的凭据提供程序,它用于访问我的S3存储桶,但从AvroParquetReader的类定义或文档中不清楚我将如何实现这一点。

推荐答案

此代码适用于我。它允许AvroParquetReader使用ProfileCredentialsProvider访问S3。

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import org.apache.parquet.avro.AvroParquetReader;
import org.apache.parquet.hadoop.ParquetReader;
import org.apache.hadoop.fs.Path;
import org.apache.avro.generic.GenericRecord;
import org.apache.hadoop.conf.Configuration;

...

final String path = "s3a://"+bucketName+"/"+pathName;
final Configuration configuration = new Configuration();
configuration.setClass("fs.s3a.aws.credentials.provider", ProfileCredentialsProvider.class,
        AWSCredentialsProvider.class);
ParquetReader<GenericRecord> parquetReader =
        AvroParquetReader.<GenericRecord>builder(new Path(path)).withConf(configuration).build();

这篇关于如何为org.apache.parquet.avro.AvroParquetReader配置S3访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆