Vaadin 14 on AWS Elastic BeanStalk
This post will guide you how to deploy a Vaadin Flow 14 Application to AWS Elastic BeanStalk. All in all it's very easy, but there are some pitfalls you should now.
First of all you should create your plattform in AWS Beanstalk (Tomcat 8.5 with Java 8 running on 64bit Amazon Linux).
![](https://slg.ddnss.de/content/images/2020/04/Bildschirmfoto-vom-2020-04-14-10-58-21.png)
Now you should build your vaadin application to a war file with your favorite buildtool, in my case maven.
My Vaadin Application uses a Connection Pool with a JNDI Resource. This is very trick to get this work because you can not change the context.xml from the tomcat installation, so you can not configure the JNDI-Resource. But there is a litte trick to get this work.
You simply have to add the context.xml in your war file in the META-INF folder.
filename.war/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/mysql" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.mariadb.jdbc.Driver"
url="jdbc:mariadb://database-name.xxxx.eu-central-1.rds.amazonaws.com:3306/dbname"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="user" password="p4ssw0rd"
maxTotal="20" maxIdle="10" maxWaitMillis="10000"/>
</Context>
In Java you can get a active connection from the pool with:
Context context = new InitialContext();
DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/mysql");
.
.
.
ds.getConnection().close();
Don't forgett to close the connection manually to get the connection back in the pool!!!
With maven you can add the following plugin to add the context.xml file from src/main/resources/META-INF to filename.war/META-INF/context.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>
${project.basedir}/src/main/resources/META-INF/
</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
Now you can upload you war file to AWS.