amazonのサンプル
そのまま動かそうとするとエラー出る
com.amazonaws.services.s3.model.AmazonS3Exception: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: 799D4ED8AD64CB1F)
デフォルトでUSのエンドポイントにアクセスしてしまう。らしい。
エンドポイントを指定したバージョン
AmazonS3 s3 = new AmazonS3Client();
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
s3.setRegion(usWest2);
s3.setEndpoint("https://s3-ap-northeast-1.amazonaws.com"); // ここでエンドポイント指定
String bucketName = "sync-dmp-test";
String key = "hoge";
s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));
これでいけた。
参考