DevOps-Life

[Spring boot] AWS Secrets Manager 연결. 본문

IT/Java

[Spring boot] AWS Secrets Manager 연결.

인풀 2023. 11. 29. 15:35
반응형
SMALL

 간단하지만 혼동되는 블로그가 많아 정리.

 aws secrets manager setting 

1. application.yml setting

2. code setting 

 

maven : 

<dependency>

<groupId>io.awspring.cloud</groupId>

<artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>

<version>2.3.3</version>

</dependency>

 

org.springframework.cloud 에서 io.awspring.cloud 로 변경 됨.

 

참조 : https://stackoverflow.com/questions/70375435/importing-secrets-in-spring-boot-application-from-aws-secrets-manager

 

Importing secrets in Spring Boot application from AWS Secrets Manager

I stored my MySQL DB credentials in AWS secrets manager using the Credentials for other database option. I want to import these credentials in my application.properties file. Based on a few answers I

stackoverflow.com

 

 

application.yml : 

 

spring:

 config:

  import: optional:aws-secretsmanager:secret/test;test2

 

세미콜론(;)으로 분리 

여러 저장소 활용 가능.

(키 값이 겹치면 어떻게 되는지는 테스트 아직 안해봄)

 

JAVA

 

@Value("${key}")

String key;

 

쉽쥬? 

 

 

+++ 추가편 

 

모든 설정은 aws cli를 셋팅 해준 뒤 진행한다. 

 

코드 내에서 가져오고 싶을때 ! 

 

https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/java/example_code/secretsmanager

 

 

이곳의 예제가 잘 나와 있으니 그대로 쓰면 된다 ...! 

반응형
LIST

'IT > Java' 카테고리의 다른 글

Java로 AI와 머신러닝? 가능할까?  (0) 2025.04.03
[JAVA] Index 1 out of bounds for length 1 Mybatis Error  (0) 2023.12.14
[JAVA] JAVA EE, Jakarta 요약  (0) 2023.09.14
Comments