Multiple databases connection in one web application - java - java

I'm hosting a web application on Amazon web services on two different elastic beanstalk environments (i.e. two different RDS instances) one for test and another for production. each time I deploy the application I need to change the connection URL according to the environment.
Is there anything I can do to automate this process? a condition for checking the environment and connecting using the right URL or something?

You should be using Elastic Beanstalk environment variables to store the database connection URL, and any other environment specific settings. Your code would simply pull the value out of the environment variable, instead of having to do some sort of check.

Related

Need automatic app restarts in Elastic BeanStalk after completing the deplyoment with using .platform

I’m currently working on a java project that will be deployed to elastic beanstalk and storing all the sensitive properties to parameter store.
My problem is I need to restart the App server on elastic beanstalk after the deployment to get those parameters to work.
I need that to be automatically picked up or automatically restart the app server.
Example:
I need to store db access details in parameter store and make them available in environment properties in elastic beanstalk and I have done that by adding a bash script file in .platform folder to get the parameters and add them to env files /opt/elasticbeanstalk/deployment/env
Referenced link: https://www.fullstackerconsulting.com/2021/09/09/how-can-i-use-the-aws-systems-manager-parameter-store-with-an-aws-elastic-beanstalk-instance-to-manage-environment-variables/
Aws: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
For demo App, I'm using java to get the properties through “System.getenv("dbusername");”
The scripts are running and I’m able to access the parameter store properties but the problem is I need to restart the App server on elastic beanstalk to work these properties.
Can you please someone suggest to me that I can run the App server automatically once the application is deployment is done?
Let me know if you need any further information related to my issue.

What's the procedure of upload a java spring based web application to the real server, and how to use load balance to the server?

I am creating a simple web project with mysql database using Java Spring-MVC. Now I want to understand the full workflow of the web system development cycle.
How to upload a project to a real server?.
How to sync the database to a real server?.
How DC and DRC is sync with each other?.
Why and how to use "Load balancer" to the server?.
Apologize, if I said something non-technical.
I'll not go into too much details but here is the gist of it.
Before anything, the first thing to get sorted is the operating system of the server be it Linux, Windows Server and so on. The choice of operating system will depend on the constraints and requirements.
How to upload a project to a real server?
Any files which needs to be served should be hosted and served by a web application server such as Apache Tomcat, IIS, Websphere and many more.
The choice of web application server depends on a few things, such as the server operating system, the web application implementation and so on. For your case, which is a Spring MVC implemented in Java, you'll need to use a web application server that supports that, such as Apache Tomcat for example.
Once the choice is made, install the web application server on the server. After that, install your web application on the web application server.
How to sync the database to a real server?
I infer that you're referring about the connectivity between the Java web application to the database? Do comment if its not.
The Spring MVC web application can connect directly to the database via JDBC or JNDI (provided that the necessary configuration is configured on the web application server).
Of course, the database can be connected locally (if installed on the same server) or remotely.
How DC and DRC is sync with each other?
This is too broad to cover and the recovery strategy differs for every Data Center providers. But broadly, they employ redundancy and replication strategy to ensure the data is always backed up and available. Check with the providers individually for a better picture.
Why and how to use "Load balancer" to the server?
The load balancer primary purpose is to distribute the work load across multiple servers to achieve better TTFB. To do so, it sits in front of the servers and routes the request accordingly. Some of the load balancing solutions such as f5 explains about load balancing in greater detail.
Step 1: Install Application Server on your machine.
Step 2: Install JDK, Database server which are dependent on your application.
Step 3: Export your war from Eclipse/Netbeans
Step 4: Paste your war file on app server's deployment folder (webapps incase of tomcat)
Step 5: your application deployed

AWS - How to share session between subdomain and domain for a Java web app?

I have a Java 8 web app running on a Tomcat 8 container that was deployed using AWS Elastic Beanstalk to an EC2 instance. I then configured Route 53 to point myapp.com to the Elastic Beanstalk endpoint as an alias, and did the same with www.myapp.com.
The problem is that when I login with either of them, the session is not shared with the other one. For example, if I login with myapp.com, and then try to access www.myapp.com, I'm being asked to login again. This problem is reproducible vice-versa and with the logout function too.
I've read this answer explaining the issue and while I understand the theory, I'm unsure on how to actually implement this. I tried pointing www.myapp.com directly to myapp.com as an alias on Route 53. I also tried configuring EB to use an Elastic Load Balancer and checked the Sticky Sessions option.
Is this something that can be configured on AWS or do I need to configure my code to accommodate this? An example would be really helpful. The application is a standard Enterprise Java web app with JSP and uses Spring Security for authentication.
Basically you need the Tomcat server to set domain="myapp.com" on every Set-Cookie header of every response.
There are many ways to do that. But the easiest way is to edit /src/resources/application.properties file in your application and set server.session.cookie.domain to myapp.com.

Linking Tomcat to MYSQL on Openshift

I've a java web application running on openshift 3 online.
I'm rather new to this platform and not familiar to the usage of service and pods.
So currently i have 2 containers running.
A. Web app
B. MYSQL
I've created environment variables to supply the MYSQL username,password,port and ip-address to the container A running the web application. However, it seem like when openshift creates a new pod, the ip-address changes. Is there any other way i could link the two container so that i don't have to rely on the ip-address?
Each service has a name/domain name. You should use their name to specify their location, rather than the IP address. Internally, the name will be resolved to the IP address.
You can find the name in the service details in the web console.

Amazon AWS WebApp with MongoDB

I have built a mobile application that needs to connect to my SpringBoot-WebApp which in turn has a MongoDB and some other things in the background.
I want to deploy this WebApp at Amazon AWS, but I am overwhelmed by all the possibilities. So far, I have just created it as a .jar, and ran it that way, and it worked fine at my other server.
Now, for traffic reasons and such, we want to move it to AWS. I have found out, that I need to create a .war instead of a .jar, which is not a problem. I then learned to upload this .war to Elastic Beanstalk. However, my application needs to connect to a MongoDB. I have logged on to AWS via SSH and installed MongoDB there and created the database, but it does not seem like this is the right way to do it.
It'd greatly appreciate if anyone could give me a hint on how to do this as I am very confused.
Thanks and best regards!
It isn't clear if you are doing this, but don't run MongoDB on Elastic Beanstalk. The Elastic Beanstalk server you have it installed on may be automatically deleted by AWS. In general you do not want to manually install anything on Elastic Beanstalk as it is a managed environment where servers may be automatically created or deleted based on server load.
Amazon doesn't provide a MongoDB service directly, so you either need to install and manage MongoDB on an EC2 instance (or fleet of instances) yourself, or use a third party MongoDB service that runs on AWS. You could use something like MongoLab which provides a MongoDB service that runs on AWS. This allows your network traffic between your web servers and database servers to stay within the AWS network, which you will want for both performance and security reasons.
If you use MongoLab just make sure you choose to create your database in the same AWS region that you are deploying your application to. Also, I wouldn't recommend their free sandbox databases for any sort of critical production application.
If you decide to install and manage MongoDB on AWS yourself, here is some documentation from Amazon, and some from MongoDB.

Categories

Resources