spring.cloud.aws.region.static not picked up (v3.3.0)
I'm trying to configure a DynamoDbClient for local integration tests but I get the error
Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain
I've been reading https://docs.awspring.io/spring-cloud-aws/docs/3.2.0/reference/html/index.html#region. I have no .aws folder, and from what I understand spring.cloud.aws.region.static should set the region.
I have my dependencies declared like this:
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:3.3.5")
mavenBom("org.springframework.cloud:spring-cloud-dependencies:2024.0.1")
}
}
dependencies {
implementation("io.awspring.cloud:spring-cloud-aws-starter")
implementation("io.awspring.cloud:spring-cloud-aws-starter-dynamodb")
implementation(platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.3.0"))
}
and an application.yaml:
spring:
cloud:
aws:
dynamodb:
endpoint: http://localhost:4566
region: eu-west-1
credentials:
access-key: dummy
secret-key: dummy
region:
static: eu-west-1
The line that fails is:
private var enhancedClient: DynamoDbEnhancedClient? = DynamoDbEnhancedClient.create()
The point is to not having to resort to environment variables or system properties but use the properties in application.yaml. Have I not set up auto configuration correct or am I misunderstanding what these properties are meant to do?
Hello @erihanse ,
When you create client on your own:
private var enhancedClient: DynamoDbEnhancedClient? = DynamoDbEnhancedClient.create()
we are not in control over it, meaning we cannot supply credentialsResolver or regionResolver.
Instead you can just autowire it, since we are creating it for you out of the box. This way we will pick values in application.yaml and use it when creating DynamoDbEnhancedClient Bean.
Now in your code class annotated with either Service Component Configuration or similar you would inject it like:
@Autowired
private val enhancedClient: DynamoDbEnhancedClient
Just note you have to include implementation("io.awspring.cloud:spring-cloud-aws-starter-dynamodb") in your project which you already did.