11package org .testcontainers .containers .localstack ;
22
3+ import com .amazonaws .auth .AWSStaticCredentialsProvider ;
4+ import com .amazonaws .auth .BasicAWSCredentials ;
35import com .amazonaws .client .builder .AwsClientBuilder ;
46import com .amazonaws .services .kms .AWSKMS ;
57import com .amazonaws .services .kms .AWSKMSClientBuilder ;
@@ -73,11 +75,22 @@ public static class WithoutNetwork {
7375
7476 @ Test
7577 public void s3TestOverBridgeNetwork () throws IOException {
78+ // with_aws_sdk_v1 {
7679 AmazonS3 s3 = AmazonS3ClientBuilder
7780 .standard ()
78- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .S3 ))
79- .withCredentials (localstack .getDefaultCredentialsProvider ())
81+ .withEndpointConfiguration (
82+ new AwsClientBuilder .EndpointConfiguration (
83+ localstack .getEndpointOverride (Service .S3 ).toString (),
84+ localstack .getRegion ()
85+ )
86+ )
87+ .withCredentials (
88+ new AWSStaticCredentialsProvider (
89+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
90+ )
91+ )
8092 .build ();
93+ // }
8194
8295 final String bucketName = "foo" ;
8396 s3 .createBucket (bucketName );
@@ -103,6 +116,7 @@ public void s3TestOverBridgeNetwork() throws IOException {
103116
104117 @ Test
105118 public void s3TestUsingAwsSdkV2 () {
119+ // with_aws_sdk_v2 {
106120 S3Client s3 = S3Client
107121 .builder ()
108122 .endpointOverride (localstack .getEndpointOverride (Service .S3 ))
@@ -113,6 +127,7 @@ public void s3TestUsingAwsSdkV2() {
113127 )
114128 .region (Region .of (localstack .getRegion ()))
115129 .build ();
130+ // }
116131
117132 final String bucketName = "foov2" ;
118133 s3 .createBucket (b -> b .bucket (bucketName ));
@@ -126,8 +141,17 @@ public void s3TestUsingAwsSdkV2() {
126141 public void sqsTestOverBridgeNetwork () {
127142 AmazonSQS sqs = AmazonSQSClientBuilder
128143 .standard ()
129- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .SQS ))
130- .withCredentials (localstack .getDefaultCredentialsProvider ())
144+ .withEndpointConfiguration (
145+ new AwsClientBuilder .EndpointConfiguration (
146+ localstack .getEndpointOverride (Service .SQS ).toString (),
147+ localstack .getRegion ()
148+ )
149+ )
150+ .withCredentials (
151+ new AWSStaticCredentialsProvider (
152+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
153+ )
154+ )
131155 .build ();
132156
133157 CreateQueueResult queueResult = sqs .createQueue ("baz" );
@@ -157,8 +181,17 @@ public void sqsTestOverBridgeNetwork() {
157181 public void cloudWatchLogsTestOverBridgeNetwork () {
158182 AWSLogs logs = AWSLogsClientBuilder
159183 .standard ()
160- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .CLOUDWATCHLOGS ))
161- .withCredentials (localstack .getDefaultCredentialsProvider ())
184+ .withEndpointConfiguration (
185+ new AwsClientBuilder .EndpointConfiguration (
186+ localstack .getEndpointOverride (Service .CLOUDWATCHLOGS ).toString (),
187+ localstack .getRegion ()
188+ )
189+ )
190+ .withCredentials (
191+ new AWSStaticCredentialsProvider (
192+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
193+ )
194+ )
162195 .build ();
163196
164197 logs .createLogGroup (new CreateLogGroupRequest ("foo" ));
@@ -172,8 +205,17 @@ public void cloudWatchLogsTestOverBridgeNetwork() {
172205 public void kmsKeyCreationTest () {
173206 AWSKMS awskms = AWSKMSClientBuilder
174207 .standard ()
175- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .KMS ))
176- .withCredentials (localstack .getDefaultCredentialsProvider ())
208+ .withEndpointConfiguration (
209+ new AwsClientBuilder .EndpointConfiguration (
210+ localstack .getEndpointOverride (Service .KMS ).toString (),
211+ localstack .getRegion ()
212+ )
213+ )
214+ .withCredentials (
215+ new AWSStaticCredentialsProvider (
216+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
217+ )
218+ )
177219 .build ();
178220
179221 String desc = String .format ("AWS CMK Description" );
@@ -198,8 +240,16 @@ public void samePortIsExposedForAllServices() {
198240 );
199241 assertEquals (
200242 "Endpoint configuration have different endpoints" ,
201- localstack .getEndpointConfiguration (Service .S3 ).getServiceEndpoint (),
202- localstack .getEndpointConfiguration (Service .SQS ).getServiceEndpoint ()
243+ new AwsClientBuilder .EndpointConfiguration (
244+ localstack .getEndpointOverride (Service .S3 ).toString (),
245+ localstack .getRegion ()
246+ )
247+ .getServiceEndpoint (),
248+ new AwsClientBuilder .EndpointConfiguration (
249+ localstack .getEndpointOverride (Service .SQS ).toString (),
250+ localstack .getRegion ()
251+ )
252+ .getServiceEndpoint ()
203253 );
204254 }
205255 }
@@ -302,8 +352,9 @@ public static class WithRegion {
302352
303353 @ Test
304354 public void s3EndpointHasProperRegion () {
305- final AwsClientBuilder .EndpointConfiguration endpointConfiguration = localstack .getEndpointConfiguration (
306- Service .S3
355+ final AwsClientBuilder .EndpointConfiguration endpointConfiguration = new AwsClientBuilder .EndpointConfiguration (
356+ localstack .getEndpointOverride (Service .S3 ).toString (),
357+ localstack .getRegion ()
307358 );
308359 assertEquals (
309360 "The endpoint configuration has right region" ,
0 commit comments