Lokesh Pandey
Lokesh Pandey

Reputation: 1789

connecting springboot application running locally to db instance running on aws VM instance

I have written a set of APIs using springboot framework. Locally its working fine. But now I am trying to test it with the postgresql database running on ec2 instance on aws.

NOTE: I am not using amazon RDS services, I have created an ec2 instance and installed postgres and configured database there.

I can see this exception being thrown when I am running my springboot application locally.

org.postgresql.util.PSQLException: The connection attempt failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:297)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)

This is the config from application.properties for one of the db

spring.xyz.datasource.jdbc-url=jdbc:postgresql://xyz.com:5432/xyz_db
spring.xyz.datasource.username=xyz
spring.xyz.datasource.password=xyz123

Am I not being able to connect because of the EC2 instance security configs ? How can I change that ?

Also it will be helpful if someone can tell me how can I make aws ec2 instance to accept the connection from only one VM ?

Upvotes: 1

Views: 540

Answers (1)

Ravindra Bagale
Ravindra Bagale

Reputation: 17665

regarding Postgress connection-

  • add below rule to security group of Ec2 instance , on which you have installed postGress
  • Allow inbound traffic to postgress port from 0.0.0.0/0 and test. ( protocol- TCP, port - 5432, IP - 0.0.0.0/0)

regarding allow from only one VM

  • add security group rule to your Ec2 instance
  • Allow inbound traffic from your VM IP only

Upvotes: 1

Related Questions