Best Python code snippet using localstack_python
config.py
Source:config.py
...26 TRUE_STRINGS,27)28# keep track of start time, for performance debugging29load_start_time = time.time()30def eval_log_type(env_var_name):31 """get the log type from environment variable"""32 ls_log = os.environ.get(env_var_name, "").lower().strip()33 return ls_log if ls_log in LOG_LEVELS else False34def is_env_true(env_var_name):35 """Whether the given environment variable has a truthy value."""36 return os.environ.get(env_var_name, "").lower().strip() in TRUE_STRINGS37def is_env_not_false(env_var_name):38 """Whether the given environment variable is empty or has a truthy value."""39 return os.environ.get(env_var_name, "").lower().strip() not in FALSE_STRINGS40# java options to Lambda41LAMBDA_JAVA_OPTS = os.environ.get("LAMBDA_JAVA_OPTS", "").strip()42# limit in which to kinesalite will start throwing exceptions43KINESIS_SHARD_LIMIT = os.environ.get("KINESIS_SHARD_LIMIT", "").strip() or "100"44# delay in kinesalite response when making changes to streams45KINESIS_LATENCY = os.environ.get("KINESIS_LATENCY", "").strip() or "500"46# Kinesis provider - either "kinesis-mock" or "kinesalite"47KINESIS_PROVIDER = os.environ.get("KINESIS_PROVIDER") or "kinesis-mock"48# default AWS region49if "DEFAULT_REGION" not in os.environ:50 os.environ["DEFAULT_REGION"] = os.environ.get("AWS_DEFAULT_REGION") or AWS_REGION_US_EAST_151DEFAULT_REGION = os.environ["DEFAULT_REGION"]52# Whether or not to handle lambda event sources as synchronous invocations53SYNCHRONOUS_SNS_EVENTS = is_env_true("SYNCHRONOUS_SNS_EVENTS")54SYNCHRONOUS_SQS_EVENTS = is_env_true("SYNCHRONOUS_SQS_EVENTS")55SYNCHRONOUS_API_GATEWAY_EVENTS = is_env_not_false("SYNCHRONOUS_API_GATEWAY_EVENTS")56SYNCHRONOUS_KINESIS_EVENTS = is_env_not_false("SYNCHRONOUS_KINESIS_EVENTS")57SYNCHRONOUS_DYNAMODB_EVENTS = is_env_not_false("SYNCHRONOUS_DYNAMODB_EVENTS")58# randomly inject faults to Kinesis59KINESIS_ERROR_PROBABILITY = float(os.environ.get("KINESIS_ERROR_PROBABILITY", "").strip() or 0.0)60# randomly inject faults to DynamoDB61DYNAMODB_ERROR_PROBABILITY = float(os.environ.get("DYNAMODB_ERROR_PROBABILITY", "").strip() or 0.0)62DYNAMODB_READ_ERROR_PROBABILITY = float(63 os.environ.get("DYNAMODB_READ_ERROR_PROBABILITY", "").strip() or 0.064)65DYNAMODB_WRITE_ERROR_PROBABILITY = float(66 os.environ.get("DYNAMODB_WRITE_ERROR_PROBABILITY", "").strip() or 0.067)68# JAVA EE heap size for dynamodb69DYNAMODB_HEAP_SIZE = os.environ.get("DYNAMODB_HEAP_SIZE", "").strip() or "256m"70# expose services on a specific host externally71HOSTNAME_EXTERNAL = os.environ.get("HOSTNAME_EXTERNAL", "").strip() or LOCALHOST72# expose SQS on a specific port externally73SQS_PORT_EXTERNAL = int(os.environ.get("SQS_PORT_EXTERNAL") or 0)74# name of the host under which the LocalStack services are available75LOCALSTACK_HOSTNAME = os.environ.get("LOCALSTACK_HOSTNAME", "").strip() or LOCALHOST76# host under which the LocalStack services are available from Lambda Docker containers77HOSTNAME_FROM_LAMBDA = os.environ.get("HOSTNAME_FROM_LAMBDA", "").strip()78# whether to remotely copy the lambda code or locally mount a volume79LAMBDA_REMOTE_DOCKER = is_env_true("LAMBDA_REMOTE_DOCKER")80# Marker name to indicate that a bucket represents the local file system. This is used for testing81# Serverless applications where we mount the Lambda code directly into the container from the host OS.82BUCKET_MARKER_LOCAL = (83 os.environ.get("BUCKET_MARKER_LOCAL", "").strip() or DEFAULT_BUCKET_MARKER_LOCAL84)85# network that the docker lambda container will be joining86LAMBDA_DOCKER_NETWORK = os.environ.get("LAMBDA_DOCKER_NETWORK", "").strip()87# custom DNS server that the docker lambda container will use88LAMBDA_DOCKER_DNS = os.environ.get("LAMBDA_DOCKER_DNS", "").strip()89# additional flags passed to Lambda Docker run/create commands90LAMBDA_DOCKER_FLAGS = os.environ.get("LAMBDA_DOCKER_FLAGS", "").strip()91# default container registry for lambda execution images92LAMBDA_CONTAINER_REGISTRY = (93 os.environ.get("LAMBDA_CONTAINER_REGISTRY", "").strip() or DEFAULT_LAMBDA_CONTAINER_REGISTRY94)95# whether to remove containers after Lambdas finished executing96LAMBDA_REMOVE_CONTAINERS = (97 os.environ.get("LAMBDA_REMOVE_CONTAINERS", "").lower().strip() not in FALSE_STRINGS98)99# directory for persisting data100DATA_DIR = os.environ.get("DATA_DIR", "").strip()101# folder for temporary files and data102TMP_FOLDER = os.path.join(tempfile.gettempdir(), "localstack")103# create folders104for folder in [DATA_DIR, TMP_FOLDER]:105 if folder and not os.path.exists(folder):106 try:107 os.makedirs(folder)108 except Exception:109 # this can happen due to a race condition when starting110 # multiple processes in parallel. Should be safe to ignore111 pass112# fix for Mac OS, to be able to mount /var/folders in Docker113if TMP_FOLDER.startswith("/var/folders/") and os.path.exists("/private%s" % TMP_FOLDER):114 TMP_FOLDER = "/private%s" % TMP_FOLDER115# temporary folder of the host (required when running in Docker). Fall back to local tmp folder if not set116HOST_TMP_FOLDER = os.environ.get("HOST_TMP_FOLDER", TMP_FOLDER)117# whether to enable verbose debug logging118LS_LOG = eval_log_type("LS_LOG")119DEBUG = is_env_true("DEBUG") or LS_LOG in TRACE_LOG_LEVELS120# whether to enable debugpy121DEVELOP = is_env_true("DEVELOP")122# PORT FOR DEBUGGER123DEVELOP_PORT = int(os.environ.get("DEVELOP_PORT", "").strip() or DEFAULT_DEVELOP_PORT)124# whether to make debugpy wait for a debbuger client125WAIT_FOR_DEBUGGER = is_env_true("WAIT_FOR_DEBUGGER")126# whether to use SSL encryption for the services127# TODO: this is deprecated and should be removed (edge port supports HTTP/HTTPS multiplexing)128USE_SSL = is_env_true("USE_SSL")129# whether to use the legacy single-region mode, defined via DEFAULT_REGION130USE_SINGLE_REGION = is_env_true("USE_SINGLE_REGION")131# whether to run in TF compatibility mode for TF integration tests132# (e.g., returning verbatim ports for ELB resources, rather than edge port 4566, etc.)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!