Reputation: 2259
I'm going to use Amazon RDS for my Spring boot web application
So, I created RDS with 'mainrds' instance id Screen Capture. then I configured application.properties
like this:
#RDS
cloud.aws.rds.mainrds
cloud.aws.rds.mainrds.username=dbadmin
cloud.aws.rds.mainrds.password=password
cloud.aws.rds.mainrds.readReplicaSupport=false
cloud.aws.rds.mainrds.databasename=maindata
When I run the application, I encountered these error messages:
Caused by: java.lang.IllegalStateException: No database instance with id:'mainrds' found. Please specify a valid db instance
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.getDbInstance(AmazonRdsDataSourceFactoryBean.java:170)
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.createDataSourceInstance(AmazonRdsDataSourceFactoryBean.java:151)
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.createInstance(AmazonRdsDataSourceFactoryBean.java:129)
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.createInstance(AmazonRdsDataSourceFactoryBean.java:45)
at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 178 common frames omitted
I can't figure out what the problem is. what is the missing point?
Upvotes: 5
Views: 2262
Reputation: 31
The accepted answer did not work for me.
After some debugging I found the application.properties as given in the question is not correct:
#RDS
cloud.aws.rds.mainrds #this line has to be deleted
cloud.aws.rds.mainrds.username=dbadmin
cloud.aws.rds.mainrds.password=password
cloud.aws.rds.mainrds.readReplicaSupport=false
cloud.aws.rds.mainrds.databasename=maindata
After deleting the line cloud.aws.rds.mainrds
everything worked just fine.
Using spring.datasource.*
is not an option because we are using IAM authentication for RDS and therefore the password has to be regenerated every 15 minutes.
Upvotes: 3
Reputation: 2101
I had the same problem.
spring-cloud-aws
probably can't resolve the proper aws region
on it's own. If you're only on one region, insert this into your properties file with the region where your RDS instance is placed.
cloud.aws.region.static=us-east-1
This solved the problem for me.
You could also try with:
cloud.aws.region.auto=true
to see if the EC2 meta data service can resolve the correct region.
It is also possible to connect via. normal spring-boot settings, where you simply specify the RDS instance endpoint in the url of the datasource like so: (for a postgresql instance)
spring.datasource.url=jdbc:postgresql://endpoint.of.rds.instance.amazonaws.com:5432/dbname
and of course supply the datasource.platform
, datasource.username
, datasource.password
, spring.database.driverClassName
and spring.jpa.database
in your application.properties aswell.
Upvotes: 6