Amazon S3到本地文件系统的级联分接配置

时间:2016-08-24 20:43:04

标签: amazon-s3 cascading

所以我正在尝试级联框架,我能够在本地运行应用程序。作为下一步,我想使用Cascading将文件从S3下载到本地文件系统。我打算使用FileTap。当我谷歌时,我发现了S3FS并且看起来像是弃用了。有人能指出我正确的方向。换句话说,使用访问ID和密钥之类的东西为Amazon S3创建FileTap的正确方法是什么。

1 个答案:

答案 0 :(得分:1)

虽然此代码适用于HadoopFlowConnector,但如果使用FileTap,这将适用于Local Flow连接器。

public class Main {
                public void run(String[] args) {
                    Properties properties = new Properties();
                    String accessKey = args[0];
                    String secretKey = args[1];
                    // better put these keys to hadoop xml file
                    // for block file system
                    properties.setProperty("fs.s3.awsAccessKeyId", accessKey);
                    properties.setProperty("fs.s3.awsSecretAccessKey", secretKey);
                    // for s3 native file system
                    // properties.setProperty("fs.s3n.awsAccessKeyId", accessKey);
                    // properties.setProperty("fs.s3n.awsSecretAccessKey", secretKey);
                    // properties.setProperty("fs.defaultFS", "hdfs://localhost:8020/");
                    // properties.setProperty("fs.permissions.umask-mode", "007");
                    AppProps.setApplicationJarClass(properties, Main.class);
                    HadoopFlowConnector flowConnector = new HadoopFlowConnector(
                        properties);
                    String input = "s3://my-bucket/my-log.csv";
                    // If using the native S3
                    // String input = "s3n://my-bucket/my-log.csv";

                    Tap inTap = new Hfs(new TextDelimited(false, ";"), input);
                    Pipe copyPipe = new Pipe("copy");
                    Tap outTap = new Hfs(new TextDelimited(false, ";"),
                        "data/output");
                    FlowDef flowDef = FlowDef.flowDef()
                        .addSource(copyPipe, inTap)
                        .addTailSink(copyPipe, outTap);
                    flowConnector.connect(flowDef).complete();
                }

                public static void main(String[] args) {
                    new Main().run(args);
                }
            }

代码礼貌http://whiteboxdeveloper.blogspot.com/2015/01/processing-data-from-aws-s3-using.html

我刚刚添加了S3N字符串输入注释行。由于我使用的是基于S3N的访问,因此我取消了S3N功能的注释并使用它。