Springboot application with supabase on AWS Elasticbeanstalk error

0

The war file is running on my local linux but not AWS Elasticbeanstalk. So i thought, could be an issue with the security group and added Outbound rules and Inbound rules for port 5432 for postgres. However, I am still getting a network error.

I have allowed and configured the appropriate incoming and outgoing traffic to the security groups and still this error happens:


25-Feb-2025 11:57:06.914 SEVERE [main] org.apache.catalina.startup.HostConfig.deployDirectory Error deploying web application directory [/var/lib/tomcat10/webapps/ROOT]
	java.lang.IllegalStateException: Error starting child
		at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:602)
		at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:571)
		at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:654)
		at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1130)
		.....
org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:467)
		at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:46)
		... 135 more
	Caused by: java.net.SocketException: Network is unreachable
		at java.base/sun.nio.ch.Net.connect0(Native Method)
		at java.base/sun.nio.ch.Net.connect(Net.java:589)
		at java.base/sun.nio.ch.Net.connect(Net.java:578)
		at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:583)
		at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
		at java.base/java.net.Socket.connect(Socket.java:751)
		at org.postgresql.core.PGStream.createSocket(PGStream.java:260)
		at org.postgresql.core.PGStream.<init>(PGStream.java:121)
		at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:140)
		at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:268)
		... 149 more
25-Feb-2025 11:57:06.930 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/var/lib/tomcat10/webapps/ROOT] has finished in [12,170] ms
25-Feb-2025 11:57:06.935 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
25-Feb-2025 11:57:06.956 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [12290] milliseconds

Also, my application.properties looks like this:

# Database Configuration

spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.datasource.driver-class-name=${SPRING_DATASOURCE_DRIVERCLASSNAME}


# JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

and my pom file looks like this:

Help. And thanks in advance!

I tried to add inbound and outbound rules.

asked 3 months ago33 views
1 Answer
0

The issue you're facing is likely due to Supabase blocking the outbound request from your Elastic Beanstalk environment. Supabase requires that all incoming connections come from IPs that have been explicitly allowlisted. When you run the application locally, your personal IP is likely already permitted. However, Elastic Beanstalk instances use dynamic IPs, which are not automatically allowed by Supabase. To resolve this, you need to route your outbound traffic through a static IP — typically done by configuring a NAT Gateway with an Elastic IP in your VPC — and then add that IP to Supabase’s IP allow list under your project’s database settings.

Aside from that, make sure your environment variables on Elastic Beanstalk are correctly set with the full JDBC URL, username, password, and driver class name. Also confirm that the PostgreSQL driver is included in your pom.xml. If you're still unsure whether it's a networking issue, SSH into the EC2 instance and try connecting to the Supabase host using telnet on port 5432. If the connection is unreachable, that confirms the IP restriction. Once the proper IP is allowlisted, the application should be able to connect without any further changes.

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions