### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

When executing samlocal deploy twice without updating the template it gets stuck after the deploy step (before the step of the output is shown)

Also i left it running for long time checking if it could finish and around 2 hours laters a kinesis stacktrace appeared on the logs on the docker container

```
localstack_main  | 2022-05-26T09:14:21.135:INFO:localstack.services.kinesis.kinesis_mock_server: [io-compute-1] WARN  2022-05-26 09:14:21,132 k.m.cache.Cache x-amzn-RequestId=3a527f8b-dcd4-11ec-ac09-ad4f3aa847a9, action=GetRecords, contextId=3a527f8a-dcd4-11ec-ac09-ad4f3aa847a9, x-amz-id-2=WLxUzW0heAIF5/pAXeHZEM0qejb1MRVum6fgYxuWPz146y+KGwkjmNwjv9IWngSM8RaihKhqcdibbhN4kruU+3p8/FlKZnTp, contentType=application/x-amz-json-1.1 - Getting records was unuccessful
localstack_main  | 2022-05-26T09:14:21.135:INFO:localstack.services.kinesis.kinesis_mock_server: kinesis.mock.ExpiredIteratorException: The shard iterator has expired. Shard iterators are only valid for 300 seconds
localstack_main  | 2022-05-26T09:14:21.135:INFO:localstack.services.kinesis.kinesis_mock_server: at kinesis.mock.models.ShardIterator.parse(ShardIterator.scala:58)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at kinesis.mock.api.GetRecordsRequest.$anonfun$getRecords$1(GetRecordsRequest.scala:24)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at cats.effect.IOFiber.runLoop(IOFiber.scala:358)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at cats.effect.IOFiber.asyncContinueSuccessfulR(IOFiber.scala:1338)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at cats.effect.IOFiber.run(IOFiber.scala:140)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:549)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:519)
localstack_main  | 2022-05-26T09:14:21.136:INFO:localstack.services.kinesis.kinesis_mock_server: at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
localstack_main  | 2022-05-26T09:14:21.140:DEBUG:localstack.services.dynamodbstreams.provider: Shard iterator for underlying kinesis stream expired
localstack_main  | 2022-05-26T09:14:21.146:INFO:localstack.utils.threads: Thread run method <bound method StreamEventSourceListener._listen_to_shard_and_invoke_lambda of <localstack.services.awslambda.event_source_listeners.dynamodb_event_source_listener.DynamoDBEventSourceListener object at 0x7fa9b98dbb50>>({'function_arn': 'arn:aws:lambda:us-west-2:000000000000:function:sandbox-events-generator-worker', 'stream_arn': 'arn:aws:dynamodb:us-west-2:000000000000:table/sandbox-events-generator-jobs/stream/2022-05-26T07:20:41.621', 'batch_size': 1, 'parallelization_factor': 1, 'lock_discriminator': '60cf3f5b-11af-4b81-840b-c62920e5f0cb/arn:aws:dynamodb:us-west-2:000000000000:table/sandbox-events-generator-jobs/stream/2022-05-26T07:20:41.621/shardId-00000001653500000000-000000000000', 'shard_id': 'shardId-00000001653500000000-000000000000', 'stream_client': <botocore.client.DynamoDBStreams object at 0x7fa9bc321810>, 'shard_iterator': 'AAAAAAAAAAEqli29q/ZrvGK0Qv58Ys0UOaNNnguVf1262Mr190addTsT21HR/XdUWnOyHg1FUUW4R774Gy1X2lmyJQMqkTKuh5nVySaVOmGBrjNRHabrLqpzejZqpTYba8lThyNRgs95fCdid2O4GmMSpaBEXElMSDpWQ/LU/Hb5NG3P0pInAfuajJsFpH8TjqTbNHNf3EBxC0OYM1EfSBu183HSLUkECOBmWfp87OOWPH+WiWiWzQ==', 'failure_destination': None, 'max_num_retries': inf}) failed: An error occurred (ExpiredIteratorException) when calling the GetRecords operation: Shard iterator has expired Traceback (most recent call last):
localstack_main  |   File "/opt/code/localstack/localstack/utils/threads.py", line 39, in run
localstack_main  |     result = self.func(self.params, **kwargs)
localstack_main  |   File "/opt/code/localstack/localstack/services/awslambda/event_source_listeners/stream_event_source_listener.py", line 182, in _listen_to_shard_and_invoke_lambda
localstack_main  |     records_response = stream_client.get_records(
localstack_main  |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 508, in _api_call
localstack_main  |     return self._make_api_call(operation_name, kwargs)
localstack_main  |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 911, in _make_api_call
localstack_main  |     raise error_class(parsed_response, operation_name)
localstack_main  | botocore.errorfactory.ExpiredIteratorException: An error occurred (ExpiredIteratorException) when calling the GetRecords operation: Shard iterator has expired
```

### Expected Behavior

the command finishes properly like in the first run

### How are you starting LocalStack?

With a docker-compose file

### Steps To Reproduce

#### How are you starting localstack (e.g., `bin/localstack` command, arguments, or `docker-compose.yml`)

docker-compose up -d

docker-compose.yml:

```
version: "3.8"

services:
  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
    image: localstack/localstack:latest
    network_mode: bridge
    ports:
      - "127.0.0.1:53:53"                # only required for Pro (DNS)
      - "127.0.0.1:53:53/udp"            # only required for Pro (DNS)
      - "127.0.0.1:443:443"              # only required for Pro (LocalStack HTTPS Edge Proxy)
      - "127.0.0.1:4510-4559:4510-4559"  # external service port range
      - "127.0.0.1:4566:4566"            # LocalStack Edge Proxy
    environment:
      - SERVICES=dynamodb,cloudformation,lambda,s3,sts,apigateway,iam
      - DEBUG=1
      - HOST_TMP_FOLDER=${TMPDIR:-/tmp/}localstack
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - "${TMPDIR:-/tmp}/localstack:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      net1:
        ipv4_address: 10.10.100.3
networks:
  net1:
    driver: bridge
    enable_ipv6: false
    ipam:
      config:
      - subnet: 10.10.100.0/24
        gateway: 10.10.100.32
```

template.yaml

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  test-sam
  
  SAM Template for test

Parameters:
  Environment:
    Type: String
    Default: sandbox
  Project:
    Type: String
    Default: project
  Component:
    Type: String
    Default: component
  DynamoDBUrl:
    Type: String
    Default: LOCALSTACK_HOSTNAME
  UseLocalstack:
    Type: String
    Default: 'true'
    AllowedValues: [true, false]

Conditions:
  UseLocalStack: !Equals [!Ref UseLocalstack, 'true']

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 360
    Environment:
      Variables:
        REGION: !Ref "AWS::Region"
        ENVIRONMENT: !Ref Environment
        PROJECT: !Ref Project
        COMPONENT: !Ref Component
        DYNAMO_DB_JOB_TABLE: !Ref JobTable
        DYNAMO_DB_URL: !Ref DynamoDBUrl

Resources:
  TestFunction:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Join [ "-", [ !Ref Environment, !Ref Component, "api" ] ]
      CodeUri: api/
      Handler: api
      Runtime: go1.x
      Architectures:
        - x86_64
      Tracing: Active
      Events:
        CatchAll:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /{proxy+}
            Method: ANY
      Environment:
        Variables:
          API_GATEWAY_V1_ENDPOINT: !Sub "http://localhost:4566/restapis/${ApiGatewayIdV1}/"
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref JobTable
        - AmazonAPIGatewayInvokeFullAccess

  WorkerFunction:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Join [ "-", [ !Ref Environment, !Ref Component, "worker" ] ]
      CodeUri: worker/
      Handler: worker
      Runtime: go1.x
      Architectures:
        - x86_64
      MemorySize: 512
      Timeout: 180
      Tracing: Active
      Events:
        JobTable:
          Type: DynamoDB
          Properties:
            Stream: !GetAtt JobTable.StreamArn
            StartingPosition: TRIM_HORIZON
            BatchSize: 1
      Environment:
        Variables:
          API_GATEWAY_ENDPOINT: !Sub "http://localhost:4566/restapis/${ApiGatewayIdV2}/"
             
          API_GATEWAY_BULK_ENDPOINT: !Sub "http://localhost:4566/restapis/${ApiGatewayIdV2}/"
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref JobTable
        - AmazonSNSFullAccess
        - AmazonAPIGatewayInvokeFullAccess

  JobTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Join [ "-", [ !Ref Environment, !Ref Component, "jobs" ] ]
      AttributeDefinitions:
        - AttributeName: Id
          AttributeType: S
      KeySchema:
        - AttributeName: Id
          KeyType: HASH
      BillingMode: PAY_PER_REQUEST
      StreamSpecification:
        StreamViewType: NEW_IMAGE


Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  EventsGeneratorAPI:
    Description: "API Gateway endpoint URL for Prod environment for First Function"
    Value: !Sub "http://localhost:4566/restapis/${ServerlessRestApi}/Prod/api/"

```

#### Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

    awslocal s3 mb s3://mybucket


### Environment

```markdown
- OS: 

MacOS Monterey 12.4

- LocalStack: 
LocalStack version: 0.14.3.1
LocalStack Docker container id: 95b639ae197e
LocalStack build date: 2022-05-25
LocalStack build git hash: 2a564393
```


### Anything else?

_No response_
stack_name = stack.stack_name
    resources = stack.resources
    if ref == "AWS::Region":
        return aws_stack.get_region()
    if ref == "AWS::Partition":
        return "aws"
    if ref == "AWS::StackName":
        return stack_name
    if ref == "AWS::StackId":
        
        return stack_name
    if ref == "AWS::AccountId":
        return get_aws_account_id()
    if ref == "AWS::NoValue":
        return PLACEHOLDER_AWS_NO_VALUE
    if ref == "AWS::NotificationARNs":
        
        return {}
    if ref == "AWS::URLSuffix":
        return AWS_URL_SUFFIX
    is_ref_attribute = attribute in ["Ref", "PhysicalResourceId", "Arn"]
    if is_ref_attribute:
        
        resource_props = resources.get(ref, {}).get("Properties")
        resolve_refs_recursively(stack, resource_props)
        return determine_resource_physical_id(