Repository: localstack/localstack

Issue:
bug: DynamoDB ResourceNotFoundException when performing BatchGetItem
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

I am receiving a ResourceNotFoundException when attempting to run a BatchGetItem operation on a table that exists.  Downgrading to `0.14.2` fixes the issue and I was not receiving this issue on Friday when running the `latest` container.  I am able to run `scan` and `query` requests successfully on these tables.

### Expected Behavior

BatchGetItem should work on tables that exist

### How are you starting LocalStack?

With a `docker run` command

### Steps To Reproduce

#### How are you starting localstack (e.g., `bin/localstack` command, arguments, or `docker-compose.yml`)

    docker run localstack/localstack

#### Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

- `awslocal dynamodb create-table --table-name test-table --attribute-definitions AttributeName=PK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1`
- `awslocal dynamodb list-tables`
```
{
    "TableNames": [
        "test-table"
    ]
}
```
- `awslocal dynamodb batch-get-item --request-items '{ "test-table": { "Keys": [{ "PK": {"S": "test-key"} }] } }'`
```
An error occurred (ResourceNotFoundException) when calling the BatchGetItem operation: Cannot do operations on a non-existent table
```

### Environment

```markdown
- OS: 
- LocalStack: latest
```


### Anything else?

_No response_
bug: DynamoDB ResourceNotFoundException when performing BatchGetItem
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

I am receiving a ResourceNotFoundException when attempting to run a BatchGetItem operation on a table that exists.  Downgrading to `0.14.2` fixes the issue and I was not receiving this issue on Friday when running the `latest` container.  I am able to run `scan` and `query` requests successfully on these tables.

### Expected Behavior

BatchGetItem should work on tables that exist

### How are you starting LocalStack?

With a `docker run` command

### Steps To Reproduce

#### How are you starting localstack (e.g., `bin/localstack` command, arguments, or `docker-compose.yml`)

    docker run localstack/localstack

#### Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

- `awslocal dynamodb create-table --table-name test-table --attribute-definitions AttributeName=PK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1`
- `awslocal dynamodb list-tables`
```
{
    "TableNames": [
        "test-table"
    ]
}
```
- `awslocal dynamodb batch-get-item --request-items '{ "test-table": { "Keys": [{ "PK": {"S": "test-key"} }] } }'`
```
An error occurred (ResourceNotFoundException) when calling the BatchGetItem operation: Cannot do operations on a non-existent table
```

### Environment

```markdown
- OS: 
- LocalStack: latest
```


### 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/).
We've got the same issue, we are using docker-compose and provisioning Dynamo tables. No changes to our stack lately and suddenly broke today (error messages of similar nature to `Cannot do operations on a non-existent table`).

Reverted to image 0.14.2 as @cmschuetz and that fixed our stack too.
We've also done the same of reverting back to 0.14.2.
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/).
We've got the same issue, we are using docker-compose and provisioning Dynamo tables. No changes to our stack lately and suddenly broke today (error messages of similar nature to `Cannot do operations on a non-existent table`).

Reverted to image 0.14.2 as @cmschuetz and that fixed our stack too.
We've also done the same of reverting back to 0.14.2.

Resolving patch:
diff --git a/localstack/services/dynamodb/provider.py b/localstack/services/dynamodb/provider.py
--- a/localstack/services/dynamodb/provider.py
+++ b/localstack/services/dynamodb/provider.py
@@ -19,6 +19,8 @@
     handler,
 )
 from localstack.aws.api.dynamodb import (
+    BatchGetItemOutput,
+    BatchGetRequestMap,
     BatchWriteItemInput,
     BatchWriteItemOutput,
     CreateGlobalTableOutput,
@@ -56,6 +58,7 @@
     ResourceArnString,
     ResourceInUseException,
     ResourceNotFoundException,
+    ReturnConsumedCapacity,
     ScanInput,
     ScanOutput,
     StreamArn,
@@ -710,6 +713,15 @@ def batch_write_item(
 
         return result
 
+    @handler("BatchGetItem")
+    def batch_get_item(
+        self,
+        context: RequestContext,
+        request_items: BatchGetRequestMap,
+        return_consumed_capacity: ReturnConsumedCapacity = None,
+    ) -> BatchGetItemOutput:
+        return self.forward_request(context)
+
     @handler("TransactWriteItems", expand=False)
     def transact_write_items(
         self,


Test patch:
diff --git a/tests/integration/test_dynamodb.py b/tests/integration/test_dynamodb.py
--- a/tests/integration/test_dynamodb.py
+++ b/tests/integration/test_dynamodb.py
@@ -977,6 +977,22 @@ def test_dynamodb_create_table_with_partial_sse_specification(self):
 
         delete_table(table_name)
 
+    def test_dynamodb_get_batch_items(self):
+        dynamodb = aws_stack.create_external_boto_client("dynamodb")
+        table_name = "ddb-table-%s" % short_uid()
+
+        dynamodb.create_table(
+            TableName=table_name,
+            KeySchema=[{"AttributeName": "PK", "KeyType": "HASH"}],
+            AttributeDefinitions=[{"AttributeName": "PK", "AttributeType": "S"}],
+            ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
+        )
+
+        result = dynamodb.batch_get_item(
+            RequestItems={table_name: {"Keys": [{"PK": {"S": "test-key"}}]}}
+        )
+        assert list(result["Responses"])[0] == table_name
+
 
 def delete_table(name):
     dynamodb_client = aws_stack.create_external_boto_client("dynamodb")