#author("2020-03-06T01:11:45+00:00","default:wikiadmin","wikiadmin") #author("2020-03-09T09:51:22+00:00","default:wikiadmin","wikiadmin") *認証情報 [#f550d5e9] 何もしないとawscliのdefaultのものが利用される。 Region region = Region.AP_NORTHEAST_1; S3Client s3 = S3Client.builder().region(region).build(); この記載だとdefaultが使われる。s3が使いたい場合はAWS_PROFILE=s3に設定して実行 [default] aws_access_key_id = hogehoge aws_secret_access_key = fugafuga [s3] aws_access_key_id = hogehoge aws_secret_access_key = fugafuga 直接設定する場合は以下のように記載 AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create("AWS KEY", "AWS PASSWORD")); S3Client s3 = S3Client.builder().credentialsProvider(creds).region(region).build(); タイムアウトの設定も別で ClientOverrideConfiguration clientOverrideConfiguration = ClientOverrideConfiguration .builder() .apiCallTimeout(props.getApiCallTimeout()) .apiCallAttemptTimeout(props.getApiCallAttemptTimeout()) .build(); S3Client s3 = S3Client .builder() .overrideConfiguration(clientOverrideConfiguration) .region(Region.AP_NORTHEAST_1).build(); Putもめんどくさい PutObjectRequest request = PutObjectRequest.builder().bucket("").key("").build(); PutObjectRequest request = PutObjectRequest.builder().bucket("バケット名").key("ファイル名のパス末尾まで!").build(); RequestBody requestBody = RequestBody.fromFile(new File("")); s3Client.putObject(request,requestBody); **認証情報が違う場合のエラー [#a66177ca] Exception in thread "main" software.amazon.awssdk.services.s3.model.S3Exception: Access Denied (Service: S3, Status Code: 403, Request ID: 4E7A2E3296DB04C2)