Skip to content

Instantly share code, notes, and snippets.

@MemoAlfa
Created October 3, 2019 11:44
Show Gist options
  • Save MemoAlfa/950ba265b8bad2ce690f371f69c5587e to your computer and use it in GitHub Desktop.
Save MemoAlfa/950ba265b8bad2ce690f371f69c5587e to your computer and use it in GitHub Desktop.
Override the Lazy initialized beans by the ones that are pointing to localstack
@Bean(destroyMethod = "shutdown")
@Primary
public AmazonSQS getSqsClient(@Value("${localstack.host}") String sqsHost, @Value("${localstack.tcp.4576}") String port) {
final AmazonSQSAsync sqsClient =
AmazonSQSAsyncClientBuilder.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(sqsHost + ":" + port, "cn-north-1"))
.withClientConfiguration(new ClientConfiguration().withProtocol(Protocol.HTTP)).build();
return sqsClient;
}
@Bean(destroyMethod = "shutdown")
@Primary
public AmazonS3 getS3Client(@Value("${localstack.host}") String s3Host,
@Value("${localstack.tcp.4572}") String port,
@Value("${s3.userDocuments.bucketName}") String userDocumentsBucket) {
final String signingRegion = "cn-north-1";
final AmazonS3 s3Client =
AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(s3Host + ":" + port, signingRegion))
.withClientConfiguration(new ClientConfiguration().withProtocol(Protocol.HTTP))
.withPathStyleAccessEnabled(true)
.disableChunkedEncoding()
.build();
s3Client.createBucket(userDocumentsBucket);
log.info("created bucket with name " + userDocumentsBucket);
return s3Client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment