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.