【问题标题】:How do I configure S3 access for org.apache.parquet.avro.AvroParquetReader?如何为 org.apache.parquet.avro.AvroParquetReader 配置 S3 访问?
【发布时间】:2019-02-04 20:53:19
【问题描述】:

我为此苦苦挣扎了一段时间,想分享我的解决方案。 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 的类定义或文档中不清楚我将如何实现这一点。

【问题讨论】:

    标签: java amazon-s3 parquet


    【解决方案1】:

    这段代码对我有用。它允许 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();
    

    【讨论】:

      【解决方案2】:

      对于其他遇到此问题的人,我发现@jd_free 的答案对我不起作用。我唯一需要更改的就是传递给AvroParquetReader 的关于AWSCredentialsProvider 使用类型的配置设置:

      Configuration configuration = new Configuration();
              configuration.set("fs.s3a.aws.credentials.provider", "org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider");
              configuration.set("fs.s3a.access.key", "KEY");
              configuration.set("fs.s3a.secret.key", "KEY");`
      

      问题在于提供的凭据提供程序,以及将其提供给配置的方式。有关不同凭证提供者的更多信息,您可以查看this page。它解释了可用于不同场景的不同类型,包括如何从环境变量中获取凭据。

      【讨论】:

        猜你喜欢
        • 2018-11-01
        • 2020-01-06
        • 1970-01-01
        • 1970-01-01
        • 2021-05-28
        • 1970-01-01
        • 1970-01-01
        • 2020-09-24
        • 1970-01-01
        相关资源
        最近更新 更多