# Type of request: This is a ...

[X] bug report
[ ] feature request

cdk / cloudformation configured api-gateway with s3 integration does not work ( the same stack works in aws ).
other services works with the same cdk code, e.g. sqs.

## Expected behavior

the stack works as in aws
 
## Actual behavior

localstack  | 2021-05-23T04:14:16:DEBUG:localstack.utils.cloudformation.template_deployer: Running action "create" for resource type "ApiGateway::Method" id "DevCustomerApiGET55FE239F"
localstack  | 2021-05-23T04:14:16:DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "ApiGateway::Method" in region us-east-1: put_method {'restApiId': 'mkj4ahf978', 'resourceId': 'umswnavo5j', 'httpMethod': 'GET', 'authorizationType': 'NONE'}
localstack  | 2021-05-23 04:14:16,380:API: Error on request:
localstack  | Traceback (most recent call last):
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 319, in run_wsgi
localstack  |     execute(self.server.app)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 308, in execute
localstack  |     application_iter = app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 178, in __call__
localstack  |     return backend_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2069, in __call__
localstack  |     return self.wsgi_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2054, in wsgi_app
localstack  |     response = self.handle_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2051, in wsgi_app
localstack  |     response = self.full_dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1501, in full_dispatch_request
localstack  |     rv = self.handle_user_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1499, in full_dispatch_request
localstack  |     rv = self.dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1485, in dispatch_request
localstack  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 156, in __call__
localstack  |     result = self.callback(request, request.url, {})
localstack  |   File "/opt/code/localstack/localstack/services/apigateway/apigateway_starter.py", line 205, in apigateway_response_integrations
localstack  |     integration_response['timeoutInMillis'] = timeout_milliseconds
localstack  | TypeError: 'NoneType' object does not support item assignment
localstack  | 2021-05-23 04:14:17,089:API: Error on request:
localstack  | Traceback (most recent call last):
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 319, in run_wsgi
localstack  |     execute(self.server.app)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 308, in execute
localstack  |     application_iter = app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 178, in __call__
localstack  |     return backend_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2069, in __call__
localstack  |     return self.wsgi_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2054, in wsgi_app
localstack  |     response = self.handle_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2051, in wsgi_app
localstack  |     response = self.full_dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1501, in full_dispatch_request
localstack  |     rv = self.handle_user_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1499, in full_dispatch_request
localstack  |     rv = self.dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1485, in dispatch_request
localstack  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 156, in __call__
localstack  |     result = self.callback(request, request.url, {})
localstack  |   File "/opt/code/localstack/localstack/services/apigateway/apigateway_starter.py", line 205, in apigateway_response_integrations
localstack  |     integration_response['timeoutInMillis'] = timeout_milliseconds
localstack  | TypeError: 'NoneType' object does not support item assignment
localstack  | 2021-05-23T04:14:18:DEBUG:localstack.utils.cloudformation.template_deployer: Extract resource attribute: ApiGateway::Deployment Ref
localstack  | 2021-05-23T04:14:18:DEBUG:localstack.services.cloudformation.cloudformation_api: Unable to resolve references in stack outputs: {'Value': {'Fn::Join': ['', ['https://', {'Ref': 'DevCustomerApiA279E14E'}, '.execute-api.', {'Ref': 'AWS::Region'}, '.', {'Ref': 'AWS::URLSuffix'}, '/', {'Ref': 'DevCustomerApiDeploymentStageprodE70041CA'}, '/']]}} - Unable to fetch details for resource "DevCustomerApiDeployment2663BF7C9972510c02f7f7a1a55860bb1c9e641c" (attribute "Ref")
localstack  | 2021-05-23 04:14:18,785:API: Error on request:
localstack  | Traceback (most recent call last):
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 319, in run_wsgi
localstack  |     execute(self.server.app)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 308, in execute
localstack  |     application_iter = app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 178, in __call__
localstack  |     return backend_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2069, in __call__
localstack  |     return self.wsgi_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2054, in wsgi_app
localstack  |     response = self.handle_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2051, in wsgi_app
localstack  |     response = self.full_dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1501, in full_dispatch_request
localstack  |     rv = self.handle_user_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1499, in full_dispatch_request
localstack  |     rv = self.dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1485, in dispatch_request
localstack  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 156, in __call__
localstack  |     result = self.callback(request, request.url, {})
localstack  |   File "/opt/code/localstack/localstack/services/apigateway/apigateway_starter.py", line 205, in apigateway_response_integrations
localstack  |     integration_response['timeoutInMillis'] = timeout_milliseconds
localstack  | TypeError: 'NoneType' object does not support item assignment
localstack  | 2021-05-23 04:14:22,219:API: Error on request:
localstack  | Traceback (most recent call last):
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 319, in run_wsgi
localstack  |     execute(self.server.app)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 308, in execute
localstack  |     application_iter = app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 178, in __call__
localstack  |     return backend_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2069, in __call__
localstack  |     return self.wsgi_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2054, in wsgi_app
localstack  |     response = self.handle_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2051, in wsgi_app
localstack  |     response = self.full_dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1501, in full_dispatch_request
localstack  |     rv = self.handle_user_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1499, in full_dispatch_request
localstack  |     rv = self.dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1485, in dispatch_request
localstack  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 156, in __call__
localstack  |     result = self.callback(request, request.url, {})
localstack  |   File "/opt/code/localstack/localstack/services/apigateway/apigateway_starter.py", line 205, in apigateway_response_integrations
localstack  |     integration_response['timeoutInMillis'] = timeout_milliseconds
localstack  | TypeError: 'NoneType' object does not support item assignment
localstack  | 2021-05-23T04:14:23:DEBUG:localstack.utils.cloudformation.template_deployer: Extract resource attribute: ApiGateway::Deployment Ref
localstack  | 2021-05-23T04:14:23:DEBUG:localstack.services.cloudformation.cloudformation_api: Unable to resolve references in stack outputs: {'Value': {'Fn::Join': ['', ['https://', {'Ref': 'DevCustomerApiA279E14E'}, '.execute-api.', {'Ref': 'AWS::Region'}, '.', {'Ref': 'AWS::URLSuffix'}, '/', {'Ref': 'DevCustomerApiDeploymentStageprodE70041CA'}, '/']]}} - Unable to fetch details for resource "DevCustomerApiDeployment2663BF7C9972510c02f7f7a1a55860bb1c9e641c" (attribute "Ref")
localstack  | 2021-05-23T04:14:24:DEBUG:localstack.utils.cloudformation.template_deployer: Error applying changes for CloudFormation stack "CustomerApiStack": An error occurred (500) when calling the PutIntegration operation (reached max retries: 4): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
localstack  | <title>500 Internal Server Error</title>
localstack  | <h1>Internal Server Error</h1>
localstack  | <p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
localstack  |  Traceback (most recent call last):
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1825, in _run
localstack  |     self.do_apply_changes_in_loop(changes, stack, stack_name)
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1876, in do_apply_changes_in_loop
localstack  |     self.apply_change(change, stack, new_resources, stack_name=stack_name)
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1929, in apply_change
localstack  |     result = deploy_resource(resource_id, new_resources, stack_name)
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 937, in deploy_resource
localstack  |     return execute_resource_action(resource_id, resources, stack_name, ACTION_CREATE)
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1041, in execute_resource_action
localstack  |     result = configure_resource_via_sdk(resource_id, resources, resource_type, func, stack_name, action_name)
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1167, in configure_resource_via_sdk
localstack  |     run_post_create_actions(action_name, resource_id, resources, resource_type, stack_name, result)
localstack  |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1232, in run_post_create_actions
localstack  |     apigateway.put_integration(
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/botocore/client.py", line 386, in _api_call
localstack  |     return self._make_api_call(operation_name, kwargs)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/botocore/client.py", line 705, in _make_api_call
localstack  |     raise error_class(parsed_response, operation_name)
localstack  | botocore.exceptions.ClientError: An error occurred (500) when calling the PutIntegration operation (reached max retries: 4): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
localstack  | <title>500 Internal Server Error</title>
localstack  | <h1>Internal Server Error</h1>
localstack  | <p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
localstack  |
localstack  |
localstack  | 2021-05-23 04:14:24,721:API: Error on request:
localstack  | Traceback (most recent call last):
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 319, in run_wsgi
localstack  |     execute(self.server.app)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 308, in execute
localstack  |     application_iter = app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 178, in __call__
localstack  |     return backend_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2069, in __call__
localstack  |     return self.wsgi_app(environ, start_response)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2054, in wsgi_app
localstack  |     response = self.handle_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2051, in wsgi_app
localstack  |     response = self.full_dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1501, in full_dispatch_request
localstack  |     rv = self.handle_user_exception(e)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
localstack  |     return cors_after_request(app.make_response(f(*args, **kwargs)))
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1499, in full_dispatch_request
localstack  |     rv = self.dispatch_request()
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1485, in dispatch_request
localstack  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
localstack  |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 156, in __call__
localstack  |     result = self.callback(request, request.url, {})
localstack  |   File "/opt/code/localstack/localstack/services/apigateway/apigateway_starter.py", line 205, in apigateway_response_integrations
localstack  |     integration_response['timeoutInMillis'] = timeout_milliseconds
localstack  | TypeError: 'NoneType' object does not support item assignment
localstack  | 2021-05-23T04:14:28:DEBUG:localstack.utils.cloudformation.template_deployer: Extract resource attribute: ApiGateway::Deployment Ref
localstack  | 2021-05-23T04:14:28:DEBUG:localstack.services.cloudformation.cloudformation_api: Unable to resolve references in stack outputs: {'Value': {'Fn::Join': ['', ['https://', {'Ref': 'DevCustomerApiA279E14E'}, '.execute-api.', {'Ref': 'AWS::Region'}, '.', {'Ref': 'AWS::URLSuffix'}, '/', {'Ref': 'DevCustomerApiDeploymentStageprodE70041CA'}, '/']]}} - Unable to fetch details for resource "DevCustomerApiDeployment2663BF7C9972510c02f7f7a1a55860bb1c9e641c" (attribute "Ref")

# Steps to reproduce

## Command used to start LocalStack

version: '3'
services:
  localstack:
    image: localstack/localstack
    container_name: localstack
    network_mode: bridge
    ports:
      - "4566:4566"
      - "4571:4571"
      - '8055:8080'
    environment:
      - SERVICES=s3,dynamodb,lambda,apigateway,cloudformation,iam,sqs,sts
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data
    volumes:
      - './.localstack:/tmp/localstack'
      - '/var/run/docker.sock:/var/run/docker.sock'

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

    const api = new apigw.RestApi(this, 'MyApi', {
          endpointTypes: [EndpointType.REGIONAL]
        });
    
    const bucket = new s3.Bucket(this, 'test-bucket');

    const executeRole = new iam.Role(this, "role", {
      assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
      path: "/service-role/"
    });

    bucket.grantReadWrite(executeRole);

    const s3Integration = new apigw.AwsIntegration({
      service: 's3',
      integrationHttpMethod: "GET",
      path:  bucket.bucketName + "/test.json",
      options : {
        credentialsRole: executeRole,
        integrationResponses: [{statusCode: '200'}]
      },
    })

    api.root.addMethod("GET",
        s3Integration, {
      methodResponses: [
        {
          statusCode: "200"
        }
      ]});



import re
import json
import binascii
import datetime
import xmltodict
from struct import pack
from binascii import crc32
from flask import Response
from requests.models import CaseInsensitiveDict, Response as RequestsResponse
from localstack.config import DEFAULT_ENCODING
from localstack.constants import TEST_AWS_ACCOUNT_ID, MOTO_ACCOUNT_ID
from localstack.utils.aws import aws_stack
from localstack.utils.common import short_uid, to_str, to_bytes, json_safe, replace_response_content
REGEX_FLAGS = re.MULTILINE | re.DOTALL
AWS_BINARY_DATA_TYPE_STRING = 7
class ErrorResponse(Exception):