public class LocalStackContainer extends org.testcontainers.containers.GenericContainer<LocalStackContainer>
Container for LocalStack, 'A fully functional local AWS cloud stack'.
withServices(Service...) should be used to select which services
are to be launched. See LocalStackContainer.Service for available choices. It is advised that
getEndpointConfiguration(Service) and
getDefaultCredentialsProvider()
be used to obtain compatible endpoint configuration and credentials, respectively.
| Modifier and Type | Class and Description |
|---|---|
static interface |
LocalStackContainer.EnabledService |
static class |
LocalStackContainer.Service |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
VERSION
Deprecated.
|
| Constructor and Description |
|---|
LocalStackContainer()
Deprecated.
use
LocalStackContainer(DockerImageName) instead |
LocalStackContainer(org.testcontainers.utility.DockerImageName dockerImageName) |
LocalStackContainer(org.testcontainers.utility.DockerImageName dockerImageName,
boolean useLegacyMode) |
LocalStackContainer(java.lang.String version)
Deprecated.
use
LocalStackContainer(DockerImageName) instead |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure() |
java.lang.String |
getAccessKey()
Provides a default access key that is preconfigured to communicate with a given simulated service.
|
com.amazonaws.auth.AWSCredentialsProvider |
getDefaultCredentialsProvider()
Provides a
AWSCredentialsProvider that is preconfigured to communicate with a given simulated service. |
com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration |
getEndpointConfiguration(LocalStackContainer.Service service)
Provides an endpoint configuration that is preconfigured to communicate with a given simulated service.
|
java.net.URI |
getEndpointOverride(LocalStackContainer.EnabledService service)
Provides an endpoint override that is preconfigured to communicate with a given simulated service.
|
java.net.URI |
getEndpointOverride(LocalStackContainer.Service service) |
java.lang.String |
getRegion()
Provides a default region that is preconfigured to communicate with a given simulated service.
|
java.lang.String |
getSecretKey()
Provides a default secret key that is preconfigured to communicate with a given simulated service.
|
LocalStackContainer |
withServices(LocalStackContainer.EnabledService... services)
Declare a set of simulated AWS services that should be launched by this container.
|
LocalStackContainer |
withServices(LocalStackContainer.Service... services) |
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, failed, finished, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, starting, stop, succeeded, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectoryclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindcopyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning@Deprecated public static final java.lang.String VERSION
@Deprecated public LocalStackContainer()
LocalStackContainer(DockerImageName) instead@Deprecated public LocalStackContainer(java.lang.String version)
LocalStackContainer(DockerImageName) insteadpublic LocalStackContainer(org.testcontainers.utility.DockerImageName dockerImageName)
dockerImageName - image name to use for Localstackpublic LocalStackContainer(org.testcontainers.utility.DockerImageName dockerImageName,
boolean useLegacyMode)
dockerImageName - image name to use for LocalstackuseLegacyMode - if true, each AWS service is exposed on a different portprotected void configure()
configure in class org.testcontainers.containers.GenericContainer<LocalStackContainer>public LocalStackContainer withServices(LocalStackContainer.Service... services)
public LocalStackContainer withServices(LocalStackContainer.EnabledService... services)
services - one or more service namespublic com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration getEndpointConfiguration(LocalStackContainer.Service service)
AmazonS3 s3 = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(localstack.getEndpointConfiguration(S3))
.withCredentials(localstack.getDefaultCredentialsProvider())
.build();
or for AWS SDK v2
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()
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.
service - the service that is to be accessedAwsClientBuilder.EndpointConfigurationpublic java.net.URI getEndpointOverride(LocalStackContainer.Service service)
public java.net.URI getEndpointOverride(LocalStackContainer.EnabledService service)
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()
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.
service - the service that is to be accessedURI endpoint overridepublic com.amazonaws.auth.AWSCredentialsProvider getDefaultCredentialsProvider()
AWSCredentialsProvider that is preconfigured to communicate with a given simulated service.
The credentials provider should be set in the AWS Java SDK when building a client, e.g.:
AmazonS3 s3 = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(localstack.getEndpointConfiguration(S3))
.withCredentials(localstack.getDefaultCredentialsProvider())
.build();
or for AWS SDK v2 you can use getAccessKey(), getSecretKey() directly:
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()
AWSCredentialsProviderpublic java.lang.String getAccessKey()
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()
public java.lang.String getSecretKey()
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()
public java.lang.String getRegion()
S3Client s3 = S3Client
.builder()
.endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(
localstack.getAccessKey(), localstack.getSecretKey()
)))
.region(Region.of(localstack.getRegion()))
.build()