title: AWS Aurora Serverless Spring Boot Communication Link Error
body: <p>I am doing a prototype for moving our Spring Boot based application to AWS Aurora DB including Serverless mode. With Provisioned mode things work as expected. However with serverless mode the application is not able to connect to the DB from EC2 instance with exception as:</p>
  <pre><code>org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'entityManagerFactory' defined in class path resource 
  [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 
  Invocation of init method failed; nested exception is javax.persistence.PersistenceException: 
  [PersistenceUnit: default] Unable to build Hibernate SessionFactory; 
  nested exception is org.hibernate.exception.JDBCConnectionException: 
  Unable to open JDBC Connection for DDL execution
  
  .....
  
  Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: 
  Communications link failure
  The last packet sent successfully to the server was 0 milliseconds ago. 
  The driver has not received any packets from the server.
  </code></pre>
  <p>I have tried reducing the initial pool size etc but still get the same error</p>
  <pre><code>spring.datasource.url=jdbc:mysql://xxxxxx.cluster-xxxxxxxxxx.us-east-1.rds.amazonaws.com:3306/db_example
  spring.datasource.username=xxxx
  spring.datasource.password=xxxxxxx
  spring.datasource.hikari.maximum-pool-size=1
  spring.datasource.hikari.minimum-idle=0
  spring.datasource.hikari.connection-timeout=60000
  spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
  ....
  </code></pre>
  <p>When I change the Datasource to SimpleDataSource or run a simple java jdbc connection from EC2 instance it works.</p>
  <pre><code>@Bean(&quot;dataSource&quot;)
  public DataSource dataSource() {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    ....
  }     
  </code></pre>
  <p>Is this normal with a Spring boot JPA/JDBC Application? Do we have to use a SimpleDriverDataSource? Perhaps are we rather supposed to use   <a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html</a>? That will probably be re-writing a lot of DB related code.</p>