", "); AwsCr" /> ", "); AwsCr" /> ", "); AwsCr"/>

java.lang.NoSuchFieldError: IDENTITY_PROVIDERS calling build method for Ec2ClientBuilder

231 Views Asked by At

Trying to get Ec2Client using following code:

AwsCredentials awsCredentials = AwsBasicCredentials.create("<ACCESS_KEY>", "<SECRET_ACCESS_KEY">);
AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(awsCredentials);
Ec2Client ec2Client = Ec2ClientBuilder.credentialsProviders(awsCredentialsProvider).region(Region.of("ap-south-1")).build;

Error :
Method threw 'java.lang.NoSuchFieldError' exception.
Cause :
java.lang.NoSuchFieldError: IDENTITY_PROVIDERS

Limited stacktrace

software.amazon.awssdk.services.ec2.DefaultEc2BaseClientBuilder.finalizeServiceConfiguration(DefaultEc2BaseClientBuilder.java:80)
software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeChildConfiguration(AwsDefaultClientBuilder.java:181)
software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration(SdkDefaultClientBuilder.java:181)
software.amazon.awssdk.services.ec2.DefaultEc2ClientBuilder.buildClient(DefaultEc2ClientBuilder.java:36)
software.amazon.awssdk.services.ec2.DefaultEc2ClientBuilder.buildClient(DefaultEc2ClientBuilder.java:25)
software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:148)
... (rest are internal classes that I'm not sure I'm allowed to show)

I found other such cases where people were having similar issue but the solution in their case was version mismatch in dependency but that is not the case here. Dependencies are declared as -

awsSdkVersion = "2.22.9"
...
aws = [
  ec2 = "software.amazon.awssdk:ec2:" + awsSdkVersion,
  sqs = "software.amazon.awssdk:sqs:" + awsSdkVersion,
  ...
]

Then, they are included in build.gradle file as implementation aws.ec2

Extra Information that may be related
When the application is launched, a static LoadingCache (google guava) calls the same code to create Ec2Client which runs with no error but when some code is run that needs to create it at that instant, I am getting this failure.

Related info -
JAVA SDK 8
AWS SDK 2.22.9
Spring Boot 2.7.7 Gradle 7.3.3

Please ask for any additional information that may be required

So far I haven't found a clue as to where I should start looking and after hours of surfing stack overflow and github issues, I'm still clueless.

0

There are 0 best solutions below