hadoop - 在Amazon Elastic MapReduce和S3中读取参数文件

标签 hadoop amazon-web-services amazon-s3 mapreduce elastic-map-reduce

我正在尝试在Amazon Elastic MapReduce系统中运行hadoop程序。我的程序从本地文件系统中获取一个输入文件,该文件包含程序运行所需的参数。但是,由于通常使用FileInputStream从本地文件系统读取文件,因此该任务在AWS环境中执行时失败,并显示一条错误消息,指出未找到参数文件。请注意,我已经将该文件上传到了Amazon S3。我该如何解决这个问题?谢谢。以下是我用来读取参数文件并因此读取文件中参数的代码。

FileInputStream fstream = new FileInputStream(path);
            FileInputStream os = new FileInputStream(fstream);
            DataInputStream datain = new DataInputStream(os);
            BufferedReader br = new BufferedReader(new InputStreamReader(datain));

            String[] args = new String[7];

            int i = 0;
            String strLine;
            while ((strLine = br.readLine()) != null) {
                args[i++] = strLine;
            }

最佳答案

如果必须从本地文件系统读取文件,则可以将EMR作业配置为使用boostrap action运行。通过该操作,只需使用s3cmd或类似文件将文件从S3复制到本地文件。

您也可以遍历Hadoop FileSystem类来读取文件,因为我很确定EMR支持这样的直接访问。例如:

FileSystem fs = FileSystem.get(new URI("s3://my.bucket.name/"), conf);
DataInputStream in = fs.open(new Path("/my/parameter/file"));

关于hadoop - 在Amazon Elastic MapReduce和S3中读取参数文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13875203/

相关文章:

python - 如何使Mapper以有序的方式从文件中获取数据

hadoop - 有什么不同的方法来安装cloudera hadoop软件包?

amazon-web-services - 如何修复 nextjs cloudfront 静态 Assets 响应 403?

python - 如何将base64编码的字符串上传到s3并在python中访问html文件中的url

sql - 从分组查询中删除连接操作

hadoop - 如何在hadoop mapreduce -matrix乘法中格式化输出

amazon-web-services - 如何在数据加载前截断 AWS Glue 作业中的 RDS 表?

python - 在 flask 弹性 beantalk 实例上运行 alembic 迁移

scala - Hadoop 中的快速递归文件夹删除

javascript - 使用 JQuery 将文件上传到带有预签名 url 的 S3 时出错