Repository: localstack/localstack

Issue:
API gateway MOCK integration internal server error
- [x] bug report
- [ ] feature request


# Detailed description

Creating an api gateway mock integration response and calling it results in an internal server error:

```
2021-04-20T22:21:22:WARNING:localstack.utils.server.http2_server: Error in proxy handler for request OPTIONS http://localhost:4566/restapis/qf25a1oyzk/stage/_user_request_/state/: 'NoneType' object has no attribute 'startswith' Traceback (most recent call last):
  File "/opt/code/localstack/localstack/utils/server/http2_server.py", line 129, in index
    raise result
  File "/opt/code/localstack/localstack/utils/bootstrap.py", line 681, in run
    result = self.func(self.params)
  File "/opt/code/localstack/localstack/utils/async_utils.py", line 28, in _run
    return fn(*args, **kwargs)
  File "/opt/code/localstack/localstack/services/generic_proxy.py", line 352, in handler
    response = modify_and_forward(method=method, path=path_with_params, data_bytes=data, headers=headers,
  File "/opt/code/localstack/localstack/services/generic_proxy.py", line 171, in modify_and_forward
    listener_result = listener.forward_request(method=method,
  File "/opt/code/localstack/localstack/services/edge.py", line 117, in forward_request
    return do_forward_request(api, method, path, data, headers, port=port)
  File "/opt/code/localstack/localstack/services/edge.py", line 136, in do_forward_request
    result = do_forward_request_inmem(api, method, path, data, headers, port=port)
  File "/opt/code/localstack/localstack/services/edge.py", line 156, in do_forward_request_inmem
    response = modify_and_forward(method=method, path=path, data_bytes=data, headers=headers,
  File "/opt/code/localstack/localstack/services/generic_proxy.py", line 171, in modify_and_forward
    listener_result = listener.forward_request(method=method,
  File "/opt/code/localstack/localstack/services/apigateway/apigateway_listener.py", line 48, in forward_request
    return invoke_rest_api_from_request(method, path, data, headers)
  File "/opt/code/localstack/localstack/services/apigateway/apigateway_listener.py", line 256, in invoke_rest_api_from_request
    return invoke_rest_api(api_id, stage, method, relative_path_w_query_params,
  File "/opt/code/localstack/localstack/services/apigateway/apigateway_listener.py", line 294, in invoke_rest_api
    return invoke_rest_api_integration(api_id, stage, integration, method, path, invocation_path, data,
  File "/opt/code/localstack/localstack/services/apigateway/apigateway_listener.py", line 307, in invoke_rest_api_integration
    if (uri.startswith('arn:aws:apigateway:') and ':lambda:path' in uri) or uri.startswith('arn:aws:lambda'):
AttributeError: 'NoneType' object has no attribute 'startswith'
```

Looks like this regression was introduced in https://github.com/localstack/localstack/pull/3539. That fits the timeline when my project stopped building.

## Expected behavior
The mock response is returned


## Actual behavior
500 Internal Server Error


# Steps to reproduce

Create a cors endpoint with type mock and no uri (I used https://github.com/bridgecrewio/terraform-aws-apigateway-cors/)

## Command used to start LocalStack

docker compose using newest localstack

## Client code (AWS SDK code snippet, or sequence of "awslocal" commands)

terraform apply



Discussion:

Resolving patch:
diff --git a/localstack/services/apigateway/apigateway_listener.py b/localstack/services/apigateway/apigateway_listener.py
--- a/localstack/services/apigateway/apigateway_listener.py
+++ b/localstack/services/apigateway/apigateway_listener.py
@@ -302,7 +302,7 @@ def invoke_rest_api_integration(api_id, stage, integration, method, path, invoca
     relative_path, query_string_params = extract_query_string_params(path=invocation_path)
     integration_type_orig = integration.get('type') or integration.get('integrationType') or ''
     integration_type = integration_type_orig.upper()
-    uri = integration.get('uri') or integration.get('integrationUri')
+    uri = integration.get('uri') or integration.get('integrationUri') or ''
 
     if (uri.startswith('arn:aws:apigateway:') and ':lambda:path' in uri) or uri.startswith('arn:aws:lambda'):
         if integration_type in ['AWS', 'AWS_PROXY']:


Test patch: