JPA cannot connect to AWS RDS from Beanstalk but it works locally - amazon-web-services

I'm deploying a Java 8 Spring Boot web app to AWS Elastic Beanstalk. I have an associated RDS MySQL instance and configured the relevant connection details.
The connection works when running the app locally, in my machine, because I set the following routing configuration for the RDS server:
As outlined, routings are also added for the security groups associated to my EC2 instances.
Therefore, running mysql on the EC2 machine works and the database can be reached.
The issue appears when deploying the app to Beanstalk, where it gets implemented into the EC2 instances. The app crashes because it gets connection refused errors when trying to connect to the MySQL RDS instance:
This doesn't seem to make any sense.
The database is accessible from both the EC2 instance (verified via the mysql command) and outside AWS, so the only remaining cause would be having misconfigured the Spring Boot app properties.
This doesn't seem to be the problem either because when running it locally, in my machine, the app has no issues connecting to the RDS instance and running normally using the production MySQL server.
I have separate application-development.properties and application-production.properties files, but I set the relevant properties to the same values:
spring.datasource.url = jdbc:mysql://XXXXXX.rds.amazonaws.com:3306/ebdb?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username = XXXXXX
spring.datasource.password = XXXXXX
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
Any pointers as to why my app could be running locally but not when deployed to Beanstalk?

Recreating both the Beanstalk environment and RDS instance seemed to fix the issue.

Related

Running an ec2 instance from other server provider existing image

I have installed ressources on a scalway server scaleway.com (a frensh servers and cloud provider). This server uses ubuntu as os and runs a python app with many installations and configs.
In scalway, you can run a new server from a server image you had before installed or already existing. In ec2 too, you can surely launch an aws ec2 instances from an existing AMI https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html.
But, is there a way please to launch an ec2 instance with a scalway image. It will save much time in deployment of the app.
Thanks.
It seems that there is no way:
https://www.reddit.com/r/Scaleway/comments/jwha9q/is_there_a_way_to_download_an_image/

AWS EC2-LINUX "Network connection refused" error

I have created AWS environment for my DEV and QA. Both the environments are created using the same CloudFormation template. DEV Environment is up and running. But I am unable to launch the QA Instance due to which our testing stopped.
When I try to login to the QA Machine it says
Network connection refused
I have checked the security groups opened port 22 on the machine. I have checked the VPC Configurations and NACLS. Everything looks fine.
What might be the issue?

Spring Cloud Config Server requires restart on AWS

I am running a spring cloud config server through AWS Elastic Beanstalk. Everything seems to work fine, but after some time (around 2 weeks) I encounter problems accessing the configurations. I get the error
Loading configuration failed
without further details on the "Whitelabel error" page of spring boot (when accessing the configuration through the browser; access through client just times out).
When I restart the config server instance on Elastic Beanstalk I can access the configuration normally again (no repository/code changes, just restart).
I suppose this is not expected behavior - I don't believe there is a "timeout" on the config server after which a restart is required.
Could it have something to do with AWS?

Connecting to RDS Postgres from Heroku

I'm in the process of migrating my Heroku app database from Heroku to AWS RDS Postgres.
On my computer, I can connect to my RDS DB using:
psql -d "postgres://user:password#XXX.rds.amazonaws.com/mydb?sslrootcert=config/amazon-rds-ca-cert.pem&sslmode=require"
However, the same psql command run from within my heroku server just hangs forever.
Also, config/amazon-rds-ca-cert.pem is the RDS certificate that I added to my package as mentioned in the documentation https://devcenter.heroku.com/articles/amazon-rds#authorizing-access-to-rds-instance and here https://stackoverflow.com/a/29467638/943524 (I did combine certificates as I am using a eu-central-1 instance).
Would someone have an idea what is blocking the connection here ?
From the sound of it, your Network ACL or Security Groups are blocking your access. It looks like they allow your computer (perhaps your entire company’s IP) but not Heroku. Check out the NACLs and Security Groups and you should find your answer (i.e. add Heroku IP range to your NACLs and/or Security Groups).

Connection pooling on glassfish server running on an Amazon ec2 instance

I had previously developed an application that I deployed on an aws beanstalk. The beanstalk ran on a tomcat server. In order to enable connection pooling in the application I followed this blog https://aws.amazon.com/blogs/aws/customize-elastic-beanstalk-using-configuration-files/ and wrote a config file to replace the server.xml file of the tomcat running on the ec2 instance. This worked perfectly for me. I am now trying to do the same thing but for an application that runs on a glassfish server. I know that I have to replace the glassfish-resources.xml file of the server but I cant figure out the path to the file on the ec2 instance. Can anyone help me with this? Thanks.