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?
When you can't connect to a DB instance, the following are common causes: Inbound rules – The access rules enforced by your local firewall and the IP addresses authorized to access your DB instance might not match. The problem is most likely the inbound rules in your security group.
A default DB parameter group is created if you make a database instance without specifying a custom DB parameter group.
Usually this means a firewall or security group is ignoring or dropping packets. Check to make sure you're not using iptables or a NAT gateway between your host and the RDS instance. If you're in a VPC, also make sure you allow egress/outbound traffic from the source host.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With