Amazon ElasticMapReduceのjarからS3上のファイルを参照する

Hadoopの制御を設定の変更で行う場合にコマンドライン引数で文字列を渡すことはできるが
パラメータが増えると引数が長くなってしまうのでファイルから設定を読み込むようにしたい

ここでは実行するjarファイルからS3上に配置したプロパティファイル読み込んでみました

public class Sample extends Configured implements Tool {
	public int run(String[] args) throws Exception {
		Configuration conf = getConf();
		String confPath = "s3n://【バケット名】/【バケット配下のパス】";
		FileSystem fs = FileSystem.get(URI.create(confPath), conf);
		Properties props = new Properties();
		props.load(fs.open(new Path(confPath)));
		/* 〜省略〜 */
	}
}

参考:File System Configuration - Amazon Elastic MapReduce

2012/09/20追記

Amazon EMRのHadoopでなくローカルのHadoop環境で実行する場合は以下のように
アクセスキーを指定することで「s3n://〜」から始まるURIにアクセスできる

Configuration conf = getConf();

conf.set("fs.s3n.awsAccessKeyId", "【AWSアクセスキー】");
conf.set("fs.s3n.awsSecretAccessKey", "【AWSシークレットキー】");

String confPath = "s3n://【バケット名】/【バケット配下のパス】";
FileSystem fs = FileSystem.get(URI.create(confPath), conf);
Properties props = new Properties();
props.load(fs.open(new Path(confPath)));