|
1 | 1 | package acc.hotsix.file_share.global.config;
|
2 | 2 |
|
| 3 | +import org.springframework.beans.factory.annotation.Value; |
3 | 4 | import org.springframework.context.annotation.Bean;
|
4 | 5 | import org.springframework.context.annotation.Configuration;
|
5 |
| -import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; |
| 6 | +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
| 7 | +import software.amazon.awssdk.auth.credentials.AwsCredentials; |
| 8 | +import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; |
| 9 | +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; |
6 | 10 | import software.amazon.awssdk.regions.Region;
|
7 | 11 | import software.amazon.awssdk.services.s3.S3Client;
|
8 | 12 | import software.amazon.awssdk.services.s3.presigner.S3Presigner;
|
9 | 13 |
|
10 | 14 | @Configuration
|
11 | 15 | public class S3Config {
|
| 16 | + |
| 17 | + @Value("${cloud.aws.credentials.access-key}") |
| 18 | + private String accessKey; |
| 19 | + |
| 20 | + @Value("${cloud.aws.credentials.secret-key}") |
| 21 | + private String secretKey; |
| 22 | + |
| 23 | + @Value("${cloud.aws.region.static}") |
| 24 | + private String region; |
| 25 | + |
| 26 | + // access, secret key 이용해 aws 자격증명 제공 |
| 27 | + @Bean |
| 28 | + public AwsCredentialsProvider awsCredentialsProvider() { |
| 29 | + AwsCredentials awsCredentials = AwsBasicCredentials.create(accessKey, secretKey); |
| 30 | + return StaticCredentialsProvider.create(awsCredentials); |
| 31 | + } |
| 32 | + |
12 | 33 | // s3서비스를 이용하기 위한 S3Client 객체 생성
|
13 | 34 | @Bean
|
14 | 35 | public S3Client s3Client() {
|
15 | 36 | return S3Client.builder()
|
16 |
| - .region(Region.AP_NORTHEAST_2) |
17 |
| - .credentialsProvider(DefaultCredentialsProvider.create()) |
| 37 | + .region(Region.of(region)) |
| 38 | + .credentialsProvider(awsCredentialsProvider()) |
18 | 39 | .build();
|
19 | 40 | }
|
20 | 41 |
|
21 | 42 | // presignedURL 을 적용하기 위한 S3Presigner 객체 생성
|
22 | 43 | @Bean
|
23 | 44 | public S3Presigner s3Presigner() {
|
24 | 45 | return S3Presigner.builder()
|
25 |
| - .region(Region.AP_NORTHEAST_2) |
26 |
| - .credentialsProvider(DefaultCredentialsProvider.create()) |
| 46 | + .region(Region.of(region)) |
| 47 | + .credentialsProvider(awsCredentialsProvider()) |
27 | 48 | .build();
|
28 | 49 | }
|
29 | 50 | }
|
0 commit comments