Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No database instance with id:' ' found. Please specify a valid db instance

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?

like image 371
makerj Avatar asked Nov 03 '15 18:11

makerj


People also ask

What are some of the common causes why you Cannot connect to a DB instance on AWS?

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.

What is applied to a DB instance if you do not specify?

A default DB parameter group is created if you make a database instance without specifying a custom DB parameter group.

Can't connect to RDS from EC2?

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.


2 Answers

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.

like image 162
Martin Hansen Avatar answered Oct 29 '22 07:10

Martin Hansen


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.

like image 27
Dominik Krüger Avatar answered Oct 29 '22 07:10

Dominik Krüger