Home > Blockchain >  Connect to RDS using AWS Secrets Manager with Cloud Starter AWS JDBC
Connect to RDS using AWS Secrets Manager with Cloud Starter AWS JDBC

Time:05-31

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!

CodePudding user response:

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

  • Related