Add a dependency to build.gradle:
testImplementation 'io.awspring.cloud:spring-cloud-aws-testcontainers'
Define a LocalStack container in TestcontainersConfiguration:
@ServiceConnection
@Bean
LocalStackContainer localStackContainer() {
return new LocalStackContainer(DockerImageName.parse("localstack/localstack:4.4.0"))
.withCopyFileToContainer(MountableFile.forClasspathResource("init-localstack.sh", 0744), "/etc/localstack/init/ready.d/init-aws.sh");
}Move init-localstack.sh to src/test/resources.
Since @ServiceConnection configures Spring Boot application to connect to LocalStack, there is no need anymore to specify credentials, region and endpoint in application.yml
spring:
cloud:
aws:
s3:
path-style-access-enabled: trueWe are not going to use docker-compose.yml. To start application locally, use TestSpringCloudAwsWorkshopApplication instead as it uses containers configured in TestcontainersConfiguration class.