简体   繁体   中英

Connect to AWS RDS using AWS Secrets Manager

I'm new to AWS and I tried to use the secrets manager to connect to an RDS database. I managed to do it with spring Datasource but I want the connection to rds to be done using the DB identifier.

I don't know exactly how to do it, this is my current application.properties

#spring.datasource.url=jdbc-secretsmanager:postgresql://database-1.c5xr47tuzrvd.us-west-2.rds.amazonaws.com/postgres
#spring.datasource.driver-class-name=com.amazonaws.secretsmanager.sql.AWSSecretsManagerPostgreSQLDriver
#spring.datasource.username=/secrets/shopping-cart/db

cloud.aws.rds.database-1.username=postgres
cloud.aws.rds.database-1.password=****
cloud.aws.rds.database-1.databaseName=postgres

Can you please guide me on how I can do it? Thank you!

Here is an AWS Doc that walks you through how to perform this use case in a Spring Boot app. In this example use case, an Aurora Serverless database is used.

Furthermore, to successfully connect to the database using the RdsDataClient object (which is part of the AWS SDK for Java V2 ), you have to set up an AWS Secrets Manager secret that is used for authentication. This doc shows you how to hook this value into the Java logic as well.

Note that you can only use the RdsDataClient object for an Aurora Serverless DB cluster or an Aurora PostgreSQL.

To use the RdsDataClient object, you require the following two Amazon Resource Name (ARN) values:

  1. An ARN of the Aurora Serverless database.
  2. An ARN of the AWS Secrets Manager secret that is used to access the database.

To read this example use case, see:

Creating the Amazon Aurora Serverless application using the AWS SDK for Java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM