1
votes

I am working on a Java application using Hibernate. I would like to deploy it on Elastic Beanstalk (Amazon Web Services) to be able to scale accordingly.

RDS is the database I want to use.

However, I do not know how to give my configuration settings to Elastic Beanstalk. Apparently it is now possible, without having to create an AMI and to use this AMI for each new server (when autoscaling).

I use :

  • hibernate.cfg.xml
  • server.xml (link to hibernate.cfg.xml)

But I want to scale easily, so no "manual configuration of EC2 instance" to input those files. So how can I give those settings to my application without the two files ?

How to deploy on Elastic Beanstalk with those info ?

2
The things i've read suggest that the way to do this is to customise the AMI, so you have a datasource available via JNDI. You can then use that one AMI for all autoscaled instances. What makes you say "apparently it is now possible, without having to create an AMI"?Tom Anderson
I read this in one of the last newsletter : "Using configuration files, you can configure software on Amazon EC2 instances within your environment, without having to create a custom AMI." maybe I misunderstood the meaningAntoine
The newsletter that says that should contain a sentence which says "To learn more about environment resources, visit the AWS Elastic Beanstalk Developer Guide.". That links to the documentation on Customizing Environment Resources, which explains how to configuring AWS resources like queues and alarms. This is not about configuring your own application, sadly.Tom Anderson
You can try creating a CloudFormation template aws.amazon.com/cloudformationVineet Bhatia

2 Answers

2
votes

Amazon Relational Database Service (RDS) is a web service to setup relational databases in the cloud. RDS supports relational database engines such as MySQL, Oracle, SqlServer. For MySQL change the hibernate.cfg.xml like below

<session-factory>
    <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property
name="connection.url">jdbc:mysql://my_sports_entertainment_db_url/news</property>
    <property name="connection.username">my_username</property>
    <property name="connection.password">my_password</property>
  </session-factory>

Also check How to 'switch' from MySQL to Amazon RDS with minimal application impact?

0
votes

I can see a way to do this, but it isn't pretty.

Your instance configuration file can include container commands. These run after the container and application are installed, but before the application is started. At this point, it is possible to edit the Tomcat context.xml file to add a datasource. The text you need to add is the usual datasource configuration. Your problem is that you have to do it from a script. The easiest thing might be to write the configuration and deliver it with your application, then use a container command to apply the mighty sed to splice it into the context.xml.

You have another problem in that the actual configuration you need to write must include things like the hostname, username, and password for RDS, which you won't have during development. AWS does expose these to Java through system properties, so the information must be on the machine somewhere. If you could find it, you could mix it into the configuration when you splice it into the context.xml.

Whilst this may be possible, as i said, it isn't pretty. It feels like a hack. There must be a better way of doing this.