Error in using aws-java-sdk-s3

user3444718 picture user3444718 · Mar 3, 2018 · Viewed 8.8k times · Source

I am trying to s3 sdk with very basic test and getting below error.

Caused by: java.lang.NoSuchFieldError: SIGNING_REGION at com.amazonaws.services.s3.AmazonS3Client.createRequest(AmazonS3Client.java:4227) at com.amazonaws.services.s3.AmazonS3Client.createRequest(AmazonS3Client.java:4203) at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:929) at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:936)

aws-java-sdk-s3

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.288</version>
</dependency

    ClientConfiguration cf = new ClientConfiguration();
    AWSCredentials credentials = new BasicAWSCredentials("<id>","<secret>");
    AmazonS3 amazonS3Client= 
    AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_1).build();
    List<Bucket> buckets = amazonS3Client.listBuckets();

Maven dependency tree:

O] --- maven-dependency-plugin:2.10:tree (default-cli) @ AwsSdkDemo ---
O] com.example:AwsSdkDemo:jar:0.0.1-SNAPSHOT
O] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.10.RELEASE:compile
O] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework.boot:spring-boot:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.10.RELEASE:compile
O] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
O] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
O] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
O] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
O] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
O] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework:spring-aop:jar:4.3.14.RELEASE:compile
O] |  |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
O] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.10.RELEASE:compile
O] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.27:compile
O] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.27:compile
O] |  |  \- org.springframework:spring-jdbc:jar:4.3.14.RELEASE:compile
O] |  +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
O] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
O] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
O] |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile
O] |  |  +- antlr:antlr:jar:2.7.7:compile
O] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
O] |  |  +- dom4j:dom4j:jar:1.6.1:compile
O] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
O] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
O] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
O] |  +- org.springframework.data:spring-data-jpa:jar:1.11.10.RELEASE:compile
O] |  |  +- org.springframework.data:spring-data-commons:jar:1.13.10.RELEASE:compile
O] |  |  +- org.springframework:spring-orm:jar:4.3.14.RELEASE:compile
O] |  |  +- org.springframework:spring-context:jar:4.3.14.RELEASE:compile
O] |  |  +- org.springframework:spring-tx:jar:4.3.14.RELEASE:compile
O] |  |  +- org.springframework:spring-beans:jar:4.3.14.RELEASE:compile
O] |  |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
O] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
O] |  \- org.springframework:spring-aspects:jar:4.3.14.RELEASE:compile
O] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.10.RELEASE:compile
O] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.10.RELEASE:compile
O] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.27:compile
O] |  |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.27:compile
O] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.27:compile
O] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.27:compile
O] |  +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
O] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
O] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
O] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
O] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
O] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
O] |  +- org.springframework:spring-web:jar:4.3.14.RELEASE:compile
O] |  \- org.springframework:spring-webmvc:jar:4.3.14.RELEASE:compile
O] |     \- org.springframework:spring-expression:jar:4.3.14.RELEASE:compile
O] +- com.amazonaws:aws-java-sdk-s3:jar:1.11.288:compile
O] |  +- com.amazonaws:aws-java-sdk-kms:jar:1.11.125:compile
O] |  +- com.amazonaws:aws-java-sdk-core:jar:1.11.125:compile
O] |  |  +- commons-logging:commons-logging:jar:1.1.3:compile
O] |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.5:compile
O] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:compile
O] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
O] |  |  +- software.amazon.ion:ion-java:jar:1.0.2:compile
O] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.10:compile
O] |  |  \- joda-time:joda-time:jar:2.9.9:compile
O] |  \- com.amazonaws:jmespath-java:jar:1.11.125:compile
O] +- com.h2database:h2:jar:1.4.196:runtime
O] +- org.projectlombok:lombok:jar:1.16.20:compile
O] \- org.springframework.boot:spring-boot-starter-test:jar:1.5.10.RELEASE:test
O]    +- org.springframework.boot:spring-boot-test:jar:1.5.10.RELEASE:test
O]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.10.RELEASE:test
O]    +- com.jayway.jsonpath:json-path:jar:2.2.0:test
O]    |  \- net.minidev:json-smart:jar:2.2.1:test
O]    |     \- net.minidev:accessors-smart:jar:1.1:test
O]    |        \- org.ow2.asm:asm:jar:5.0.3:test
O]    +- junit:junit:jar:4.12:test
O]    +- org.assertj:assertj-core:jar:2.6.0:test
O]    +- org.mockito:mockito-core:jar:1.10.19:test
O]    |  \- org.objenesis:objenesis:jar:2.1:test
O]    +- org.hamcrest:hamcrest-core:jar:1.3:test
O]    +- org.hamcrest:hamcrest-library:jar:1.3:test
O]    +- org.skyscreamer:jsonassert:jar:1.4.0:test
O]    |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
O]    +- org.springframework:spring-core:jar:4.3.14.RELEASE:compile
O]    \- org.springframework:spring-test:jar:4.3.14.RELEASE:test
O] ------------------------------------------------------------------------

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>AwsSdkDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AwsSdkDemo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Edgware.SR2</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.288</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
            <version>1.11.288</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

Answer

user3444718 picture user3444718 · Mar 3, 2018

Thank you everyone, issue was with having not consistent version of aws-core dependency that is pulled by spring. After manually giving core version (1.11.288) it resolves issue. As mentioned if we just not put version explicitly in pom in spring boot, it can also resolve this issue.