LocalstackSession

class pytest_localstack.session.LocalstackSession(docker_client, services=None, region_name='us-east-1', kinesis_error_probability=0.0, dynamodb_error_probability=0.0, container_log_level=10, localstack_verison='latest', auto_remove=True, pull_image=True, container_name=None, use_ssl=False, **kwargs)[source]

Run a localstack Docker container.

This class can start and stop a Localstack container, as well as capture its logs. It also implments a plugin system to add factories for the various AWS client libraries (botocore, boto3, etc).

Can be used as a context manager:

>>> import docker
>>> client = docker.from_env()
>>> with LocalstackSession(client) as session:
...     s3 = session.boto3.resource('s3')
Parameters:
  • docker_client – A docker-py Client object that will be used to talk to Docker.
  • services (list|dict, optional) –

    One of

    • A list of AWS service names to start in the Localstack container.
    • A dict of service names to the port they should run on.

    Defaults to all services. Setting this can reduce container startup time and therefore test time.

  • region_name (str, optional) – Region name to assume. Each Localstack container acts like a single AWS region. Defaults to ‘us-east-1’.
  • kinesis_error_probability (float, optional) – Decimal value between 0.0 (default) and 1.0 to randomly inject ProvisionedThroughputExceededException errors into Kinesis API responses.
  • dynamodb_error_probability (float, optional) – Decimal value between 0.0 (default) and 1.0 to randomly inject ProvisionedThroughputExceededException errors into DynamoDB API responses.
  • container_log_level (int, optional) – The logging level to use for Localstack container logs. Defaults to logging.DEBUG.
  • localstack_verison (str, optional) – The version of the Localstack image to use. Defaults to latest.
  • auto_remove (bool, optional) – If True, delete the Localstack container when it stops.
  • container_name (str, optional) – The name for the Localstack container. Defaults to a randomly generated id.
  • use_ssl (bool, optional) – If True use SSL to connect to Localstack. Default is False.
  • **kwargs – Additional kwargs will be stored in a kwargs attribute in case test resource factories want to access them.