Skip to content

Commit 80909ca

Browse files
committed
s3 application.yml 작성 및 관련 코드 작성
1 parent 490b34c commit 80909ca

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

spring/s3-application-yml.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,59 @@
66

77
### s3 application.yml
88

9+
```
10+
cloud:
11+
aws:
12+
s3:
13+
bucket: <버킷명>
14+
credentials:
15+
accessKey: <accessKey 입력>
16+
secretKey: <secretKey 입력>
17+
region:
18+
static: <버킷 region설정>
19+
auto: false //region 자동 감지
20+
stack:
21+
auto: false // CloudFormation 사용 안하기
22+
```
23+
924
s3를 사용하기 위해서 application.yml 설정을 진행했다. accesskey와 secretkey만 있으면 되는 줄 알았는데
1025
cloud.aws.stack.auto를 안해줘서 문제가 생겼다. ec2에서 프로그램을 실행하면 자동으로 Cloud Formation가 실행되는 데 이게 문제가 되어 실행이 안된다고 한다.
26+
27+
나는 aws 관련해서 사용할 때 property를 만들어서 사용한다. 테스트를 할 때 @Value가 동작하지 않아 문제가 많이 생겼던 기억이 있기에 이를 방지하기 위해 다음과 같은 코드를 작성해서 사용한다.
28+
29+
```java
30+
import lombok.Getter;
31+
import lombok.NoArgsConstructor;
32+
import org.springframework.beans.factory.annotation.Value;
33+
import org.springframework.stereotype.Component;
34+
35+
@Component
36+
@Getter
37+
@NoArgsConstructor
38+
public class AwsProperty {
39+
40+
@Value("${cloud.aws.credentials.accessKey}")
41+
private String accessKey;
42+
43+
@Value("${cloud.aws.credentials.secretKey}")
44+
private String secretKey;
45+
46+
@Value("${cloud.aws.s3.bucket}")
47+
private String bucket;
48+
49+
@Value("${cloud.aws.region.static}")
50+
private String region;
51+
52+
public AwsProperty(String accessKey, String secretKey, String bucket, String region) {
53+
this.accessKey = accessKey;
54+
this.secretKey = secretKey;
55+
this.bucket = bucket;
56+
this.region = region;
57+
}
58+
}
59+
```
60+
61+
이런식으로 만들어서 서비스 코드에 생성자에 넣어주면 사용하기 편하다.
62+
이와 관련된 코드를 예전에 작성한게 있어 여기에 링크를 올려놓는다.
63+
64+
[object storage java code](https://github.com/tae2089/spring-objectstorage)

0 commit comments

Comments
 (0)