I have a ledger-based database "demo" inside AWS qLdB. So I want to connect to that database through the Spring boot web application.
First of all, I gave user permissions to QLDB like
Then I added the following maven dependencies to pom.
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-qldb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-qldb</artifactId>
<version>1.12.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.ion/ion-java -->
<dependency>
<groupId>software.amazon.ion</groupId>
<artifactId>ion-java</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>software.amazon.qldb</groupId>
<artifactId>amazon-qldb-driver-java</artifactId>
<version>2.3.1</version>
</dependency>
In Application.yml i kept these properties.
cloud:
aws:
credentials:
access-key:
secret-key:
region: US East (Ohio)
Then I create a config class to connect to QLDB like.
@Configuration
public class QldbConfigs {
public static IonSystem ionSys = IonSystemBuilder.standard().build();
public static QldbDriver qldbDriver;
@Bean
public void setupDb(){
System.out.println("Initializing the driver");
qldbDriver = QldbDriver.builder()
.ledger("demo")
.transactionRetryPolicy(RetryPolicy
.builder()
.maxRetries(3)
.build())
.sessionClientBuilder(QldbSessionClient.builder())
.build();
}
}
If I run this, it is giving an exception like
software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@6076c66: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@57b1ec84: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@5a82bc58: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@5d37aa0f: Unable to contact EC2 metadata service.]
How can I fix this issue?