Class LocalStackContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<LocalStackContainer>
org.testcontainers.localstack.LocalStackContainer
All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<LocalStackContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class LocalStackContainer extends org.testcontainers.containers.GenericContainer<LocalStackContainer>
Testcontainers implementation for LocalStack.

Supported images: localstack/localstack, localstack/localstack-pro

Exposed ports: 4566

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    LocalStackContainer(String dockerImageName)
     
    LocalStackContainer(org.testcontainers.utility.DockerImageName dockerImageName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
    containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
     
    Provides a default access key that is preconfigured to communicate with a given simulated service.
    Provides an endpoint to communicate with LocalStack service.
    Provides a default region that is preconfigured to communicate with a given simulated service.
    Provides a default secret key that is preconfigured to communicate with a given simulated service.
    withServices(String... services)
    Declare a set of simulated AWS services that should be launched by this container.

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, 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, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, stop, 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, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Constructor Details

    • LocalStackContainer

      public LocalStackContainer(String dockerImageName)
      Parameters:
      dockerImageName - image name to use for Localstack
    • LocalStackContainer

      public LocalStackContainer(org.testcontainers.utility.DockerImageName dockerImageName)
      Parameters:
      dockerImageName - image name to use for Localstack
  • Method Details

    • configure

      protected void configure()
      Overrides:
      configure in class org.testcontainers.containers.GenericContainer<LocalStackContainer>
    • containerIsStarting

      protected void containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
      Overrides:
      containerIsStarting in class org.testcontainers.containers.GenericContainer<LocalStackContainer>
    • withServices

      public LocalStackContainer withServices(String... services)
      Declare a set of simulated AWS services that should be launched by this container.
      Parameters:
      services - one or more service names
      Returns:
      this container object
    • getEndpoint

      public URI getEndpoint()
      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.:
      S3Client s3 = S3Client
                   .builder()
                   .endpointOverride(localstack.getEndpoint())
                   .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.

      Returns:
      an URI endpoint
    • getAccessKey

      public String getAccessKey()
      Provides a default access key that is preconfigured to communicate with a given simulated service. AWS Access Key The access key can be used to construct AWS SDK v2 clients:
      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()
           
      Returns:
      a default access key
    • getSecretKey

      public String getSecretKey()
      Provides a default secret key that is preconfigured to communicate with a given simulated service. AWS Secret Key The secret key can be used to construct AWS SDK v2 clients:
      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()
           
      Returns:
      a default secret key
    • getRegion

      public String getRegion()
      Provides a default region that is preconfigured to communicate with a given simulated service. The region can be used to construct AWS SDK v2 clients:
      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()
           
      Returns:
      a default region