Skip to content

spring.cloud.aws.region.static not picked up (v3.3.0) #1366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
erihanse opened this issue Mar 29, 2025 · 1 comment
Open

spring.cloud.aws.region.static not picked up (v3.3.0) #1366

erihanse opened this issue Mar 29, 2025 · 1 comment

Comments

@erihanse
Copy link

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?

@MatejNedic
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants