Skip to content
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

ForcePathStyle has been configured on both S3Configuration and the client/global level #1292

Closed
wangyue82lf opened this issue Dec 13, 2024 · 2 comments
Labels
component: s3 S3 integration related issue

Comments

@wangyue82lf
Copy link

Type: Bug

Component:
S3

Describe the bug
Using io.awspring.cloud version 3.2.1
Using dependencies: spring-cloud-aws-starter and spring-cloud-aws-starter-s3.
Also using software.amazon.awssdk:apache-client:2.25.70 to customize AWSClient.

Sample
S3 pathStyle can't configure by auto-configured.

Plese reference to demo from the attachement.
demo.zip

@maciejwalkowiak maciejwalkowiak added component: s3 S3 integration related issue type: bug Something isn't working labels Dec 13, 2024
@maciejwalkowiak maciejwalkowiak added this to the 3.3.0 M2 milestone Dec 13, 2024
@maciejwalkowiak
Copy link
Contributor

The problem seems to be not with Spring Cloud AWS but with AWS SDK itself or it is by design.

In your code you inject S3ClientBuilder and call build() on it. Autoconfiguration already builds S3 client using the same builder, so it this is the second time to build() method call on the same builder. And it just throws excpetion like this:

java.lang.IllegalStateException: ForcePathStyle has been configured on both S3Configuration and the client/global level. Please limit ForcePathStyle configuration to one location.

	at software.amazon.awssdk.utils.Validate.validState(Validate.java:423)
	at software.amazon.awssdk.services.s3.DefaultS3BaseClientBuilder.finalizeServiceConfiguration(DefaultS3BaseClientBuilder.java:142)
	at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeChildConfiguration(AwsDefaultClientBuilder.java:169)
	at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration(SdkDefaultClientBuilder.java:198)
	at software.amazon.awssdk.services.s3.DefaultS3ClientBuilder.buildClient(DefaultS3ClientBuilder.java:37)
	at software.amazon.awssdk.services.s3.DefaultS3ClientBuilder.buildClient(DefaultS3ClientBuilder.java:26)
	at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:165)

You can reproduce it easily with testing pure builder:

class S3ClientBuilderTest {

    @Test
    void foo() {
        S3ClientBuilder s3ClientBuilder = S3Client.builder()
                .region(Region.AF_SOUTH_1)
                .serviceConfiguration(c -> c.pathStyleAccessEnabled(true));
        s3ClientBuilder.build();
        s3ClientBuilder.build();
    }
}

In your specific sample I think you can just inject S3Client instead of builder. Let me know if it helps

@maciejwalkowiak maciejwalkowiak removed this from the 3.3.0 M2 milestone Dec 14, 2024
@maciejwalkowiak maciejwalkowiak added status: waiting-for-feedback Waiting for feedback from issuer and removed type: bug Something isn't working labels Dec 14, 2024
@wangyue82lf
Copy link
Author

Thanks for your help

@maciejwalkowiak maciejwalkowiak removed the status: waiting-for-feedback Waiting for feedback from issuer label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: s3 S3 integration related issue
Projects
None yet
Development

No branches or pull requests

2 participants