[AWS] AWS System Manager로 민감한 설정 정보 관리하기: 3.0 최신 버전

Rupee·2023년 6월 22일
0

삽질기록

목록 보기
19/27
post-thumbnail

☁️ 서브모듈 단점

기존에 설정 정보 민감한 데이터를 감추려고, 서브 모듈을 이용했었다.

하지만 매번 데이터를 동기화 하는 과정이 너무 귀찮았고, 또한 실수로 submodule update 를 안한 경우 설정 정보가 맞지 않아 수시로 에러가 발생했었다.

AWS를 사용해보자!

AWS System Manager에서는 parameter store 라는 저장 공간을 제공해준다.

1. Spring Cloud AWS 의존성 추가

dependencies {
  implementation(platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.0"))
  implementation("io.awspring.cloud:spring-cloud-aws-starter-parameter-store")
}

항상 현재 Spring Boot 버전에 맞는 외부 라이브러리의 버전을 적용시켜야 한다는 것에 주의하자.

https://github.com/awspring/spring-cloud-aws

2. yml 파일 세팅하기

config:
  type: aws-parameterstore:/config/pumping

spring:
  config:
    import: ${config.type}

yml 파일에 aws parameterstoreconfig.pumping.{XXX} 형태로 저장해주고 싶다면, import 영역에 최종 루트 경로를 지정해주면 된다.

https://docs.awspring.io/spring-cloud-aws/docs/3.0.0/reference/html/index.html#spring-cloud-aws-parameter-store

Spring Cloud/ Spring Boot version compatibility checks have failed: Spring Boot [3.1.0] is not compatible with this Spring Cloud release train / action = 'Change Spring Boot version to one of the following versions [3.0.x] .

스프링 클라우드 버전과 맞지 않아서, 다시 스프링 부트 버전을 3.0.4 로 낮춰 주었다.

☁️ 트러블 슈팅

  1. yml 설정 과정

나 같은 경우는 문서대로 똑같이 했더니 계속 빨간색 줄이 뜨면서 인식을 못했다. 따라서 config.type 으로 따로 빼주었더니 인식에 성공했다.

  1. Could not resolve placeholder 에러

하지만 이상하게도 Could not resolve placeholder 관련 에러가 났다. 쉽게 말하면 해당 내용을 찾아올 수 없다는 것인데, 역시 이럴때는 디버깅이 답니다.

로그를 유심히 보니 ParameterStorePropertySources 에서 프로퍼티들을 불러오는데까지 성공한 것 같아서, 그 이후 로그에 찍힌 클래스 중 하나에 체크포인트를 걸어 디버깅 해보았다.

Loading property from AWS Parameter Store with name: /config/pumping, optional: false

public class ParameterStorePropertySource extends AwsPropertySource<ParameterStorePropertySource, SsmClient> {

    private final Map<String, Object> properties = new LinkedHashMap<>();
    ...
    
	@Override
	public void init() {
		GetParametersByPathRequest paramsRequest = GetParametersByPathRequest.builder().path(context).recursive(true)
				.withDecryption(true).build();
		getParameters(paramsRequest);
	}
}

알고 보니 getParameters 메서드에서 keymongo.uri도 아니고 /mongo.uri도 아닌 .mongo.uri 로 바꾸고 있어서 계속 에러가 났던 것이다. 따라서 아래와 같이 다시 수정해주니 정상적으로 값이 불러와졌다.

profile
개인용으로 공부하는 공간입니다. 잘못된 부분은 피드백 부탁드립니다!

1개의 댓글

comment-user-thumbnail
2023년 12월 31일

좋은 정보 잘 보고 갑니다.
감사합니다.

답글 달기