Skip to content

Allow using LocalStackContainer with AWS SDK v2 #1442#2579

Merged
rnorth merged 5 commits intotestcontainers:masterfrom
musketyr:master
Apr 23, 2020
Merged

Allow using LocalStackContainer with AWS SDK v2 #1442#2579
rnorth merged 5 commits intotestcontainers:masterfrom
musketyr:master

Conversation

@musketyr
Copy link
Copy Markdown
Contributor

This PR exposes the generated URI from the getEndpointConfiguration(Service) method
so it can be used by AWS SDK v2 methods.

It also exposes the default access key, secret key and region which is also required by the clients.

AWS SDK v2 users will be able to use the container without additional changes as follows:

S3Client s3 = S3Client
             .builder()
             .endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
             .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
                localstack.getDefaultAccessKey(), localstack.getDefaultSecretKey()
             )))
             .region(Region.of(localstack.getDefaultRegion()))
             .build()

@musketyr musketyr requested a review from bsideup April 16, 2020 08:28
@bsideup bsideup added this to the next milestone Apr 16, 2020
@bsideup
Copy link
Copy Markdown
Member

bsideup commented Apr 16, 2020

@musketyr do you know if AWS SDK 1 and 2 can co-exist on the same classpath?
If so, could you please add a test (and maybe use it to add "Usage example with AWS SDK 2" docs section via the code include block)?

@musketyr
Copy link
Copy Markdown
Contributor Author

@bsideup test and docs added. I've kept the copy-pasted as it was before. see ba3a73c

final software.amazon.awssdk.services.s3.model.Bucket bucket = buckets.get(0);

assertEquals("The created bucket has the right name", "foo", bucket.name());
assertEquals("The created bucket has the right name", "foo", bucket.name());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals("The created bucket has the right name", "foo", bucket.name());
assertEquals("The created bucket has the right name", "foo", bucket.name());

duplicate

}

@Test
public void s3TestOverBridgeNetworkV2() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think test's name is a bit too specific
  2. could you please reduce the test to the minimum, so that it only tests that SDK v2 works fine?

@musketyr musketyr requested a review from bsideup April 23, 2020 07:01
@rnorth
Copy link
Copy Markdown
Member

rnorth commented Apr 23, 2020

LGTM - will merge. Thanks for the contribution @musketyr!

@rnorth rnorth changed the title Minimal changes to allow using LocalStackContainer with AWS SDK v2 #1442 Allow using LocalStackContainer with AWS SDK v2 #1442 Apr 23, 2020
@rnorth rnorth merged commit 12de2b4 into testcontainers:master Apr 23, 2020
quincy pushed a commit to quincy/testcontainers-java that referenced this pull request May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants