# Buggy code
def forward_request(self, method, path, data, headers):
    if method == "OPTIONS":
        return 200

    # kill the process if we receive this header
    headers.get(HEADER_KILL_SIGNAL) and os._exit(0)

    target = headers.get("x-amz-target", "")
    auth_header = headers.get("authorization", "")
    host = headers.get("host", "")
    headers[HEADER_LOCALSTACK_EDGE_URL] = "https://%s" % host

    # extract API details
    api, port, path, host = get_api_from_headers(headers, path)

    if port and int(port) < 0:
        return 404

    if not port:
        port = get_port_from_custom_rules(method, path, data, headers) or port

    if not port:
        if api in ["", None, "_unknown_"]:
            truncated = truncate(data)
            LOG.info(
                (
                    'Unable to find forwarding rule for host "%s", path "%s", '
                    'target header "%s", auth header "%s", data "%s"'
                )
                % (host, path, target, auth_header, truncated)
            )
        else:
            LOG.info(
                (
                    'Unable to determine forwarding port for API "%s" - please '
                    "make sure this API is enabled via the SERVICES configuration"
                )
                % api
            )
        response = Response()
        response.status_code = 404
        response._content = '{"status": "running"}'
        return response

    use_ssl = config.USE_SSL

    connect_host = "%s:%s" % (config.HOSTNAME, port)
    url = "http%s://%s%s" % ("s" if use_ssl else "", connect_host, path)
    headers["Host"] = host
    function = getattr(requests, method.lower())
    if isinstance(data, dict):
        data = json.dumps(data)

    response = function(url, data=data, headers=headers, verify=False)
    return response


# Traceback (TypeError)
2020-06-09T11:04:42:ERROR:localstack.services.dynamodb.dynamodb_starter: DynamoDB health check failed: an integer is required (got type NoneType) Traceback (most recent call last):
File "/opt/code/localstack/localstack/services/dynamodb/dynamodb_starter.py", line 23, in check_dynamodb
wait_for_port_open(PORT_DYNAMODB_BACKEND, http_path='/', expect_success=False, sleep_time=1)
File "/opt/code/localstack/localstack/utils/common.py", line 412, in wait_for_port_open
return retry(check, sleep=sleep_time, retries=retries)
File "/opt/code/localstack/localstack/utils/common.py", line 460, in retry
raise raise_error
File "/opt/code/localstack/localstack/utils/common.py", line 456, in retry
return function(**kwargs)
File "/opt/code/localstack/localstack/utils/common.py", line 409, in check
if not is_port_open(port, http_path=http_path, expect_success=expect_success):
File "/opt/code/localstack/localstack/utils/common.py", line 392, in is_port_open
result = sock.connect_ex((host, port))
TypeError: an integer is required (got type NoneType)

# Fixed code
def forward_request(self, method, path, data, headers):
    if method == "OPTIONS":
        return 200

    if path.split("?")[0] == "/health":
        return serve_health_endpoint(method, path, data)

    # kill the process if we receive this header
    headers.get(HEADER_KILL_SIGNAL) and os._exit(0)

    target = headers.get("x-amz-target", "")
    auth_header = headers.get("authorization", "")
    host = headers.get("host", "")
    headers[HEADER_LOCALSTACK_EDGE_URL] = "https://%s" % host

    # extract API details
    api, port, path, host = get_api_from_headers(headers, path)

    if port and int(port) < 0:
        return 404

    if not port:
        port = get_port_from_custom_rules(method, path, data, headers) or port

    if not port:
        if api in ["", None, "_unknown_"]:
            truncated = truncate(data)
            LOG.info(
                (
                    'Unable to find forwarding rule for host "%s", path "%s", '
                    'target header "%s", auth header "%s", data "%s"'
                )
                % (host, path, target, auth_header, truncated)
            )
        else:
            LOG.info(
                (
                    'Unable to determine forwarding port for API "%s" - please '
                    "make sure this API is enabled via the SERVICES configuration"
                )
                % api
            )
        response = Response()
        response.status_code = 404
        response._content = '{"status": "running"}'
        return response

    use_ssl = config.USE_SSL

    connect_host = "%s:%s" % (config.HOSTNAME, port)
    url = "http%s://%s%s" % ("s" if use_ssl else "", connect_host, path)
    headers["Host"] = host
    function = getattr(requests, method.lower())
    if isinstance(data, dict):
        data = json.dumps(data)

    response = function(url, data=data, headers=headers, verify=False)
    return response