Repository: localstack/localstack

Issue:
bug: Unable to set -inMemory for Dynamodb
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

There's no way to explicitly toggle the `-inMemory` flag for DynamoDB - it relies on [`db_path` being unset](https://github.com/localstack/localstack/blob/v1.0.1/localstack/services/dynamodb/server.py#L45). However, `db_path` is always set because it [relies on config.dirs.data](https://github.com/localstack/localstack/blob/v1.0.1/localstack/services/dynamodb/server.py#L107-L113), which is [always set](https://github.com/localstack/localstack/blob/v1.0.1/localstack/config.py#L119).

### Expected Behavior

Maybe have an explicit env var like `DYNAMODB_IN_MEMORY` to force `-inMemory` mode or fix the path based logic in which it can be enabled.

Use case: I'm running tests on an ephemeral localstack container and don't need persistence. I think I'm experiencing the performance hit in https://github.com/localstack/localstack/issues/1205 and `-inMemory` seems be significantly faster.

### How are you starting LocalStack?

With a docker-compose file

### Steps To Reproduce

`docker-compose.yml`
```yaml
version: '3.8'
services:
  localstack:
    image: localstack/localstack:1.0
    environment:
      - EDGE_PORT=4566
      - EAGER_SERVICE_LOADING=1
      - SERVICES=dynamodb
      - PERSISTENCE=0
```

```
$ docker-compose up
...
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : Initializing DynamoDB Local with the following configuration:
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : Port:	34585
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : InMemory:	false
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : DbPath:	/var/lib/localstack/tmp/state/dynamodb
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : SharedDb:	false
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : shouldDelayTransientStatuses:	false
localstack_1      | 2022-07-23T05:27:50.506  INFO --- [   Thread-12] l.services.dynamodb.server : CorsParams:	*
...
```

### Environment

```markdown
- OS: Docker on Mac M1
- LocalStack: 1.0.1
```


### Anything else?

_No response_


Discussion:
Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our [Slack Community](https://localstack.cloud/contact/) for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our [contributing guidelines](https://github.com/localstack/.github/blob/main/CONTRIBUTING.md) and our [developer guide](https://docs.localstack.cloud/developer-guide/).
adding the `-inMemory` if `PERSISTENCE=0` seems the most user friendly. maybe adding an option to overwrite it would be good though, something like `DYNAMODB_IN_MEMORY` to be consistent with the others: https://docs.localstack.cloud/localstack/configuration/#dynamodb
Is there any update on how to set -inMemory = true?

Resolving patch:
diff --git a/localstack/config.py b/localstack/config.py
--- a/localstack/config.py
+++ b/localstack/config.py
@@ -711,6 +711,7 @@ def in_docker():
     "DOCKER_BRIDGE_IP",
     "DYNAMODB_ERROR_PROBABILITY",
     "DYNAMODB_HEAP_SIZE",
+    "DYNAMODB_IN_MEMORY",
     "DYNAMODB_SHARE_DB",
     "DYNAMODB_READ_ERROR_PROBABILITY",
     "DYNAMODB_WRITE_ERROR_PROBABILITY",
diff --git a/localstack/services/dynamodb/server.py b/localstack/services/dynamodb/server.py
--- a/localstack/services/dynamodb/server.py
+++ b/localstack/services/dynamodb/server.py
@@ -105,6 +105,11 @@ def create_dynamodb_server(
     port = port or get_free_tcp_port()
     server = DynamodbServer(port)
     db_path = f"{config.dirs.data}/dynamodb" if not db_path and config.dirs.data else db_path
+
+    if is_env_true("DYNAMODB_IN_MEMORY"):
+        # the DYNAMODB_IN_MEMORY variable takes precedence and will set the DB path to None which forces inMemory=true
+        db_path = None
+
     if db_path:
         if clean_db_path:
             rm_rf(db_path)


Test patch: