aws/aws-secretsmanager-jdbc

Exception while using with AWS Java SDK

jainikpurohit opened this issue · 4 comments

I am using AWS SDK for java on my project and now want to use AWS secrets manager to store RDS details. while integrating aws-secretsmanager-jdbc, getting a below error while running a query against database:

java.lang.NoSuchFieldError: SERVICE_ID
	at com.amazonaws.services.secretsmanager.AWSSecretsManagerClient.executeDescribeSecret(AWSSecretsManagerClient.java:885)
	at com.amazonaws.services.secretsmanager.AWSSecretsManagerClient.describeSecret(AWSSecretsManagerClient.java:866)
	at com.amazonaws.secretsmanager.caching.cache.SecretCacheItem.executeRefresh(SecretCacheItem.java:102)
	at com.amazonaws.secretsmanager.caching.cache.SecretCacheItem.executeRefresh(SecretCacheItem.java:32)
	at com.amazonaws.secretsmanager.caching.cache.SecretCacheObject.refresh(SecretCacheObject.java:188)
	at com.amazonaws.secretsmanager.caching.cache.SecretCacheObject.getSecretValue(SecretCacheObject.java:286)
	at com.amazonaws.secretsmanager.caching.SecretCache.getSecretString(SecretCache.java:123)
	at com.amazonaws.secretsmanager.sql.AWSSecretsManagerDriver.connectWithSecret(AWSSecretsManagerDriver.java:321)
	at com.amazonaws.secretsmanager.sql.AWSSecretsManagerDriver.connect(AWSSecretsManagerDriver.java:384)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

I did some research and found out that this might be the version conflict issue between sdk-core and secretsmanager. Here is the maven dependency tree:

[INFO] |  +- software.amazon.awssdk:secretsmanager:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:aws-json-protocol:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:protocol-core:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:sdk-core:jar:2.10.30:compile
[INFO] |  |  |  \- software.amazon.awssdk:profiles:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:auth:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:http-client-spi:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:regions:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:annotations:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:utils:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:aws-core:jar:2.10.30:compile
[INFO] |  |  +- software.amazon.awssdk:apache-client:jar:2.10.30:runtime
[INFO] |  |  \- software.amazon.awssdk:netty-nio-client:jar:2.10.30:runtime
[INFO] +- com.amazonaws.secretsmanager:aws-secretsmanager-jdbc:jar:1.0.3:compile
[INFO] |  +- com.amazonaws.secretsmanager:aws-secretsmanager-caching-java:jar:1.0.0:compile
[INFO] |  +- com.amazonaws:aws-java-sdk-secretsmanager:jar:1.11.418:compile
[INFO] |  |  +- com.amazonaws:aws-java-sdk-core:jar:1.11.281:compile
[INFO] |  |  \- com.amazonaws:jmespath-java:jar:1.11.281:compile
[INFO] +- software.amazon.awssdk:secretsmanager:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:aws-json-protocol:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:protocol-core:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:sdk-core:jar:2.10.30:compile
[INFO] |  |  \- software.amazon.awssdk:profiles:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:auth:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:http-client-spi:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:regions:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:annotations:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:utils:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:aws-core:jar:2.10.30:compile
[INFO] |  +- software.amazon.awssdk:apache-client:jar:2.10.30:runtime
[INFO] |  \- software.amazon.awssdk:netty-nio-client:jar:2.10.30:runtime
[INFO] \- com.amazonaws:aws-java-sdk-s3:jar:1.11.281:compile
[INFO]    \- com.amazonaws:aws-java-sdk-kms:jar:1.11.281:compile

FYI, I am using bom file for AWS JAVA SDK and that has version 2.5.47 while aws-secretsmanager-jdbc have AWS JAVA SDK version 1.11.418

Figured this out, its the issue happening because of wrong version of core library. I was trying to use AWS SDK 2.x and 1.x in the same project so I had this version conflict.

Fixed by adding versions to pom as below:

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
            <version>1.11.418</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>jmespath-java</artifactId>
            <version>1.11.418</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-secretsmanager</artifactId>
            <version>1.11.418</version>
        </dependency>

what did your pom file look like before that change?

I did not have those dependencies in my pom but I have AWS SDK 2.x dependency in the project where I am using this module.

It looks like this was addressed with commit: 221472a. This commit was tested with SDK version 1.11.806. Closing this out in favor of that commit.