aws lambda error loading redshift jdbc driver

2019-08-01 06:40发布

问题:

I get below error when trying to load Redshift jdbc jar from Aws Lambda.

java.io.IOException: Unable to load driver: JAR expected but not found. java.sql.SQLException: No suitable driver found for jdbc:redshift://insightlyanalytics.c0ubofza4jil.us-west-2.redshift.amazonaws.com:5439/analytics;user=xxxh;password=xxx at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:270) at com.insightly.GeoPerformanceReports.updateRedshiftTable(GeoPerformanceReports.java:154)

code to load the jar is as below..

Class.forName("com.amazon.redshift.jdbc42.Driver");

Redshift jar is located in the jar file uploaded to Lambda.

pom.xml dependency looks as below.

    <dependency>
        <groupId>com.amazon.redshift</groupId>
        <artifactId>redshift-jdbc42-no-awssdk</artifactId>
        <version>1.2.10.1009</version>
    </dependency>        
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.255</version>
    </dependency>

I am unable to figure out what is going wrong.

回答1:

It was a bug in particular 1.2.10.1009 version, where class couldn't be loaded from jar with space in filename. They claim they fixed it in latest version