最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon s3 - What url should I use for S3 url when using Testharness? - Stack Overflow

programmeradmin0浏览0评论

I have an application that has a config that fails if the s3 bucket is unavailable.

I add the following to my test application.yaml

s3:
  access.key: "testAccessKey"
  secret.key: "testSecretKey"
  url: http://doesntmatter

Then I start but I get

Factory method 's3Client' threw exception with message: Failed to initialize S3 bucket

This makes sense as the url doesn't exist so I would like to use testharness. I set it up with...

    @Bean
    fun localStackContainer(): LocalStackContainer {
        val localStack = LocalStackContainer(DockerImageName.parse("localstack/localstack:latest"))
            .withServices(LocalStackContainer.Service.S3)
        localStack.start()
        return localStack
    }

    @Bean
    @Primary
    fun s3Client(localStack: LocalStackContainer): S3Client {
        return S3Client.builder()
            .endpointOverride(URI.create(localStack.getEndpointOverride(LocalStackContainer.Service.S3).toString()))
            .credentialsProvider(
                StaticCredentialsProvider.create(
                    AwsBasicCredentials.create(localStack.accessKey, localStack.secretKey)
                )
            )
            .region(Region.of(localStack.region))
            .build()
    }

but once I do this I still get....

Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to execute HTTP request: doesntmatter

What url am I supposed to use and how do I set it as an application property?

Is there a better option? I don't need anything robust like a functioning test harness, just a mock proxying the s3 endpoint would be fine but I can't get that working either.

发布评论

评论列表(0)

  1. 暂无评论