An example of Spring Boot application that connects to AWS Secrets Manager to get database credentials.
Read this blog post for more details.
Create an AWS Secret from your AWS Management Console, name it as local-test
.
If you don't know how to that, read this article.
If you already have the secret but with a different name, make sure to edit application.properties
, and change spring.datasource.username
field.
Need to export the following environment variables in the same console that you run the application,
$ export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
$ export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY
$ export AWS_REGION=YOUR_ACCOUNT_REGION
$ cd docker && docker-compose up -d
$ ./db_initializer.sh
$ ./mvnw spring-boot:run
Open your browser and hit localhost:8080/v1/users/
. You should see JSON output.
To change any values like database name, port, host or even the secret name, either change the application properties or export the environment variables.