7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

aws-sdk-for-javaでs3にファイルを置こうとするとThe bucket you are attempting to access must be addressed using the specified endpoint.

Last updated at Posted at 2015-09-18

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()));

これでいけた。

参考

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?