Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ public URI getEndpointOverride(EnabledService service) {
}
}

/**
* Provides an endpoint to communicate with LocalStack service.
* The provided endpoint should be set in the AWS Java SDK v2 when building a client, e.g.:
* <pre><code>S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpoint())
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()
</code></pre>
* <p><strong>Please note that this method is only intended to be used for configuring AWS SDK clients
* that are running on the test host. If other containers need to call this one, they should be configured
* specifically to do so using a Docker network and appropriate addressing.</strong></p>
*
* @return an {@link URI} endpoint
*/
public URI getEndpoint() {
try {
final String address = getHost();
// resolve IP address and use that as the endpoint so that path-style access is automatically used for S3
String ipAddress = InetAddress.getByName(address).getHostAddress();
return new URI("http://" + ipAddress + ":" + getMappedPort(PORT));
} catch (UnknownHostException | URISyntaxException e) {
throw new IllegalStateException("Cannot obtain endpoint URL", e);
}
}

private int getServicePort(EnabledService service) {
return legacyMode ? service.getPort() : PORT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void s3TestOverBridgeNetwork() throws IOException {
.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
localstack.getEndpointOverride(Service.S3).toString(),
localstack.getEndpoint().toString(),
localstack.getRegion()
)
)
Expand Down Expand Up @@ -115,7 +115,7 @@ public void s3TestUsingAwsSdkV2() {
// with_aws_sdk_v2 {
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(Service.S3))
.endpointOverride(localstack.getEndpoint())
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())
Expand All @@ -138,7 +138,7 @@ public void sqsTestOverBridgeNetwork() {
.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
localstack.getEndpointOverride(Service.SQS).toString(),
localstack.getEndpoint().toString(),
localstack.getRegion()
)
)
Expand Down Expand Up @@ -171,7 +171,7 @@ public void cloudWatchLogsTestOverBridgeNetwork() {
.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
localstack.getEndpointOverride(Service.CLOUDWATCHLOGS).toString(),
localstack.getEndpoint().toString(),
localstack.getRegion()
)
)
Expand All @@ -195,7 +195,7 @@ public void kmsKeyCreationTest() {
.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
localstack.getEndpointOverride(Service.KMS).toString(),
localstack.getEndpoint().toString(),
localstack.getRegion()
)
)
Expand Down Expand Up @@ -345,7 +345,7 @@ public static class WithRegion {
@Test
public void s3EndpointHasProperRegion() {
final AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
localstack.getEndpointOverride(Service.S3).toString(),
localstack.getEndpoint().toString(),
localstack.getRegion()
);
assertThat(endpointConfiguration.getSigningRegion())
Expand All @@ -366,7 +366,7 @@ public void s3ServiceStartLazily() {
try (
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(Service.S3))
.endpointOverride(localstack.getEndpoint())
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())
Expand Down