Skip to content

Commit ba3a73c

Browse files
committed
added example to the documentation
1 parent 3d7ceb8 commit ba3a73c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/modules/localstack.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public LocalStackContainer localstack = new LocalStackContainer()
1313

1414
@Test
1515
public void someTestMethod() {
16+
// AWS SDK v1
1617
AmazonS3 s3 = AmazonS3ClientBuilder
1718
.standard()
1819
.withEndpointConfiguration(localstack.getEndpointConfiguration(S3))
@@ -21,6 +22,19 @@ public void someTestMethod() {
2122

2223
s3.createBucket("foo");
2324
s3.putObject("foo", "bar", "baz");
25+
26+
// AWS SDK v2
27+
S3Client s3 = S3Client
28+
.builder()
29+
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
30+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
31+
localstack.getAccessKey(), localstack.getSecretKey()
32+
)))
33+
.region(Region.of(localstack.getRegion()))
34+
.build();
35+
36+
s3.createBucket(b -> b.bucket("foo"));
37+
s3.putObject(b -> b.bucket("foo").key("bar"), RequestBody.fromBytes("baz".getBytes()));
2438
```
2539

2640
Environment variables listed in [Localstack's README](https://github.com/localstack/localstack#configurations) may be used to customize Localstack's configuration.

modules/localstack/src/test/java/org/testcontainers/containers/localstack/LocalstackContainerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void s3TestOverBridgeNetwork() throws IOException {
9393
}
9494

9595
@Test
96-
public void s3TestOverBridgeNetworkV2() throws IOException {
96+
public void s3TestOverBridgeNetworkV2() {
9797
S3Client s3 = S3Client
9898
.builder()
9999
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))

0 commit comments

Comments
 (0)