# Type of request: This is a ...

[ X] bug report
[ ] feature request

# Detailed description
Deploying the exact same CloudFormation template to localstack will sometimes succeed and sometimes fail (tested deploying templates immediately after starting localstack with persistent data off).

## Expected behavior
The template will successfully deploy consistently.

## Actual behavior
The templates deployment is sometimes successful and sometimes fails.

Logs when deployment failed:
```log
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_listener: Download CloudFormation template content from local S3: awswrappers-cf-templates-306001320082-none - 2020-12-09_12-35-40-601-slack-sns-topic
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: None
2020-12-09T12:35:52:INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
2020-12-09T12:35:52:DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource SnsTopic not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
2020-12-09T12:35:52:INFO:localstack.services.cloudformation.cloudformation_starter: Resource SnsTopic cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}} (existing: {'AWS::Partition', 'AWS::StackId', 'AWS::StackName', 'AWS::Region', 'AWS::URLSuffix', 'Environment', 'AWS::AccountId'})
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
2020-12-09T12:35:52:DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource PermissionForSnsToInvokeLambda not yet deployed: SnsTopic {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}}
2020-12-09T12:35:52:INFO:localstack.services.cloudformation.cloudformation_starter: Resource PermissionForSnsToInvokeLambda cannot be deployed, found unsatisfied dependencies. ['SnsTopic'] - {'Type': 'AWS::Lambda::Permission', 'Properties': {'FunctionName': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Action': 'lambda:InvokeFunction', 'Principal': 'sns.amazonaws.com', 'SourceArn': {'Ref': 'SnsTopic'}}} (existing: {'AWS::Partition', 'AWS::StackId', 'AWS::StackName', 'AWS::Region', 'AWS::URLSuffix', 'Environment', 'AWS::AccountId'})
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: None
2020-12-09T12:35:52:DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource LambdaFunction not yet deployed: LambdaFunctionRole {'Type': 'AWS::IAM::Role', 'Properties': {'AssumeRolePolicyDocument': {'Version': '2012-10-17', 'Statement': [{'Effect': 'Allow', 'Principal': {'Service': ['lambda.amazonaws.com']}, 'Action': ['sts:AssumeRole']}]}, 'Path': '/', 'Policies': [{'PolicyName': 'slack-sns-topic', 'PolicyDocument': {'Statement': [{'Effect': 'Allow', 'Action': ['logs:*'], 'Resource': 'arn:aws:logs:*:*:*'}]}}], 'RoleName': 'cf-slack-sns-topic-LambdaFunctionRole'}}
2020-12-09T12:35:52:INFO:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunction cannot be deployed, found unsatisfied dependencies. ['LambdaFunctionRole'] - {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}} (existing: {'AWS::Partition', 'AWS::StackId', 'AWS::StackName', 'AWS::Region', 'AWS::URLSuffix', 'Environment', 'AWS::AccountId'})
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionLogGroup: None
2020-12-09T12:35:52:INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
2020-12-09T12:35:52:DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource LambdaFunctionLogGroup not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
2020-12-09T12:35:52:INFO:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionLogGroup cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::Logs::LogGroup', 'DependsOn': 'LambdaFunction', 'Properties': {'RetentionInDays': 7, 'LogGroupName': {'Fn::Join': ['', ['/aws/lambda/', {'Ref': 'LambdaFunction'}]]}}} (existing: {'AWS::Partition', 'AWS::StackId', 'AWS::StackName', 'AWS::Region', 'AWS::URLSuffix', 'Environment', 'AWS::AccountId'})
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionRole: None
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionRole need not be deployed (is_updateable=False): {'Type': 'AWS::IAM::Role', 'Properties': {'AssumeRolePolicyDocument': {'Version': '2012-10-17', 'Statement': [{'Effect': 'Allow', 'Principal': {'Service': ['lambda.amazonaws.com']}, 'Action': ['sts:AssumeRole']}]}, 'Path': '/', 'Policies': [{'PolicyName': 'slack-sns-topic', 'PolicyDocument': {'Statement': [{'Effect': 'Allow', 'Action': ['logs:*'], 'Resource': 'arn:aws:logs:*:*:*'}]}}], 'RoleName': 'cf-slack-sns-topic-LambdaFunctionRole', 'RoleId': 'xudhnvha4059a1e51j9x', 'Arn': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'CreateDate': datetime.datetime(2020, 12, 9, 2, 35, 52, 904000, tzinfo=tzutc()), 'MaxSessionDuration': 3600}} True
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 1
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 4 unresolved dependencies in loop iteration 1
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: None
2020-12-09T12:35:52:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: None
2020-12-09T12:35:53:INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource SnsTopic not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
2020-12-09T12:35:53:INFO:localstack.services.cloudformation.cloudformation_starter: Resource SnsTopic cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}} (existing: {'AWS::Partition', 'AWS::StackId', 'AWS::StackName', 'LambdaFunctionRole', 'AWS::Region', 'AWS::URLSuffix', 'Environment', 'AWS::AccountId'})
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: True
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Unable to resolve attribute reference ['LambdaFunction', 'Arn'] in resource map keys ['SnsTopic', 'PermissionForSnsToInvokeLambda', 'LambdaFunctionLogGroup', 'LambdaFunctionRole', 'LambdaFunction']
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: True
2020-12-09T12:35:53:INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
2020-12-09T12:35:53:INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Deploying CloudFormation resource (update=False, exists=False, updateable=False): {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': 'ci'}}}}
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Running action "create" for resource type "Lambda::Function" id "LambdaFunction"
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_listener: Error response for CloudFormation action "CreateStack" (500) POST /: b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n'
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "Lambda::Function" in region us-east-1: create_function {'FunctionName': 'forward-sns-messages-to-slack', 'Runtime': 'python3.7', 'Role': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'Handler': 'index.handler', 'Code': {'ZipFile': b'PK\x03\x04\x14\x00\x00\x00\x00\x00zd\x89QuQ\x92\x1bo\x00\x00\x00o\x00\x00\x00\x08\x00\x00\x00index.pyimport json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\nPK\x01\x02\x14\x03\x14\x00\x00\x00\x00\x00zd\x89QuQ\x92\x1bo\x00\x00\x00o\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00index.pyPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x006\x00\x00\x00\x95\x00\x00\x00\x00\x00'}, 'Environment': {'Variables': {'AWS_ACCOUNT': 'ci'}}, 'Timeout': 20}
2020-12-09 12:35:53,118:API: Error on request:
Traceback (most recent call last):
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 323, in run_wsgi
    execute(self.server.app)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 312, in execute
    application_iter = app(environ, start_response)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 173, in __call__
    return backend_app(environ, start_response)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 151, in __call__
    result = self.callback(request, request.url, {})
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/core/responses.py", line 202, in dispatch
    return cls()._dispatch(*args, **kwargs)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/core/responses.py", line 312, in _dispatch
    return self.call_action()
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/core/responses.py", line 397, in call_action
    response = method()
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/cloudformation/responses.py", line 95, in create_stack
    stack = self.cloudformation_backend.create_stack(
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/cloudformation/models.py", line 589, in create_stack
    self._validate_export_uniqueness(new_stack)
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/cloudformation/models.py", line 761, in _validate_export_uniqueness
    new_stack_export_names = [x.name for x in stack.exports]
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/cloudformation/models.py", line 346, in exports
    return self.output_map.exports
  File "/home/tobolov/linrepos/localstack/.venv/lib/python3.8/site-packages/moto/cloudformation/parsing.py", line 774, in exports
    cleaned_value = clean_json(value.get("Value"), self._resource_map)
  File "/home/tobolov/linrepos/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 306, in clean_json
    raise DependencyNotYetSatisfied(
localstack.services.cloudformation.cloudformation_starter.DependencyNotYetSatisfied: Unable to resolve attribute ref ['LambdaFunction', 'Arn']
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: True
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: True
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource PermissionForSnsToInvokeLambda not yet deployed: SnsTopic {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}}
2020-12-09T12:35:53:INFO:localstack.services.cloudformation.cloudformation_starter: Resource PermissionForSnsToInvokeLambda cannot be deployed, found unsatisfied dependencies. ['SnsTopic'] - {'Type': 'AWS::Lambda::Permission', 'Properties': {'FunctionName': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Action': 'lambda:InvokeFunction', 'Principal': 'sns.amazonaws.com', 'SourceArn': {'Ref': 'SnsTopic'}}} (existing: {'AWS::Partition', 'AWS::StackId', 'AWS::StackName', 'LambdaFunctionRole', 'AWS::Region', 'AWS::URLSuffix', 'LambdaFunction', 'Environment', 'AWS::AccountId'})
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionLogGroup: None
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Extract resource attribute: Lambda::Function PhysicalResourceId
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionLogGroup need not be deployed (is_updateable=False): {'Type': 'AWS::Logs::LogGroup', 'DependsOn': 'LambdaFunction', 'Properties': {'RetentionInDays': 7, 'LogGroupName': '/aws/lambda/forward-sns-messages-to-slack', 'logGroupName': '/aws/lambda/forward-sns-messages-to-slack', 'creationTime': 1607481353026, 'metricFilterCount': 0, 'arn': 'arn:aws:logs:us-east-1:000000000000:log-group:/aws/lambda/forward-sns-messages-to-slack', 'storedBytes': 0}} True
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 2
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 2 unresolved dependencies in loop iteration 2
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: None
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Deploying CloudFormation resource (update=False, exists=False, updateable=False): {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': 'arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack', 'Protocol': 'lambda'}]}}
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Running action "create" for resource type "SNS::Topic" id "SnsTopic"
2020-12-09T12:35:53:DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "SNS::Topic" in region us-east-1: create_topic {'Name': 'slack-sns-topic'}
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
2020-12-09T12:35:53:WARNING:moto: No Moto CloudFormation support for AWS::Lambda::Permission
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 3
2020-12-09T12:35:53:DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 0 unresolved dependencies in loop iteration 3
2020-12-09T12:35:55:DEBUG:localstack.services.cloudformation.cloudformation_listener: Download CloudFormation template content from local S3: awswrappers-cf-templates-306001320082-none - 2020-12-09_12-35-40-601-slack-sns-topic
2020-12-09T12:35:55:DEBUG:localstack.services.cloudformation.cloudformation_listener: Error response for CloudFormation action "CreateStack" (400) POST /: b'<ErrorResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/"><Error><Type>Sender</Type><Code>AlreadyExistsException</Code><Message>Stack [slack-sns-topic] already exists</Message></Error><RequestId>950ff8d7-812a-44b3-bb0c-9b271b954104</RequestId></ErrorResponse>'
```

Logs when deployment succeeded:
```log
DEBUG:localstack.services.cloudformation.cloudformation_listener: Download CloudFormation template content from local S3: awswrappers-cf-templates-306001320082-none - 2020-12-09_12-54-05-886-slack-sns-topic
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: None
INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource SnsTopic not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource SnsTopic cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}} (existing: {'Environment', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource PermissionForSnsToInvokeLambda not yet deployed: SnsTopic {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource PermissionForSnsToInvokeLambda cannot be deployed, found unsatisfied dependencies. ['SnsTopic'] - {'Type': 'AWS::Lambda::Permission', 'Properties': {'FunctionName': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Action': 'lambda:InvokeFunction', 'Principal': 'sns.amazonaws.com', 'SourceArn': {'Ref': 'SnsTopic'}}} (existing: {'Environment', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: None
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource LambdaFunction not yet deployed: LambdaFunctionRole {'Type': 'AWS::IAM::Role', 'Properties': {'AssumeRolePolicyDocument': {'Version': '2012-10-17', 'Statement': [{'Effect': 'Allow', 'Principal': {'Service': ['lambda.amazonaws.com']}, 'Action': ['sts:AssumeRole']}]}, 'Path': '/', 'Policies': [{'PolicyName': 'slack-sns-topic', 'PolicyDocument': {'Statement': [{'Effect': 'Allow', 'Action': ['logs:*'], 'Resource': 'arn:aws:logs:*:*:*'}]}}], 'RoleName': 'cf-slack-sns-topic-LambdaFunctionRole'}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunction cannot be deployed, found unsatisfied dependencies. ['LambdaFunctionRole'] - {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}} (existing: {'Environment', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionLogGroup: None
INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource LambdaFunctionLogGroup not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionLogGroup cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::Logs::LogGroup', 'DependsOn': 'LambdaFunction', 'Properties': {'RetentionInDays': 7, 'LogGroupName': {'Fn::Join': ['', ['/aws/lambda/', {'Ref': 'LambdaFunction'}]]}}} (existing: {'Environment', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionRole: None
DEBUG:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionRole need not be deployed (is_updateable=False): {'Type': 'AWS::IAM::Role', 'Properties': {'AssumeRolePolicyDocument': {'Version': '2012-10-17', 'Statement': [{'Effect': 'Allow', 'Principal': {'Service': ['lambda.amazonaws.com']}, 'Action': ['sts:AssumeRole']}]}, 'Path': '/', 'Policies': [{'PolicyName': 'slack-sns-topic', 'PolicyDocument': {'Statement': [{'Effect': 'Allow', 'Action': ['logs:*'], 'Resource': 'arn:aws:logs:*:*:*'}]}}], 'RoleName': 'cf-slack-sns-topic-LambdaFunctionRole', 'RoleId': '37o5r0uv8yjv3czlrjkk', 'Arn': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'CreateDate': datetime.datetime(2020, 12, 9, 2, 54, 15, 823000, tzinfo=tzutc()), 'MaxSessionDuration': 3600}} True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 1
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: None
DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 4 unresolved dependencies in loop iteration 1
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: None
INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource SnsTopic not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource SnsTopic cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}} (existing: {'Environment', 'LambdaFunctionRole', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource PermissionForSnsToInvokeLambda not yet deployed: SnsTopic {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource PermissionForSnsToInvokeLambda cannot be deployed, found unsatisfied dependencies. ['SnsTopic'] - {'Type': 'AWS::Lambda::Permission', 'Properties': {'FunctionName': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Action': 'lambda:InvokeFunction', 'Principal': 'sns.amazonaws.com', 'SourceArn': {'Ref': 'SnsTopic'}}} (existing: {'Environment', 'LambdaFunctionRole', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionLogGroup: None
INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
DEBUG:localstack.services.cloudformation.cloudformation_starter: Deploying CloudFormation resource (update=False, exists=False, updateable=False): {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': 'ci'}}}}
DEBUG:localstack.utils.cloudformation.template_deployer: Running action "create" for resource type "Lambda::Function" id "LambdaFunction"
INFO:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource LambdaFunctionLogGroup not yet deployed: LambdaFunction {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': {'Fn::GetAtt': ['LambdaFunctionRole', 'Arn']}, 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': {'Fn::Select': [1, {'Fn::Split': ['-', {'Ref': 'Environment'}]}]}}}}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionLogGroup cannot be deployed, found unsatisfied dependencies. ['LambdaFunction'] - {'Type': 'AWS::Logs::LogGroup', 'DependsOn': 'LambdaFunction', 'Properties': {'RetentionInDays': 7, 'LogGroupName': {'Fn::Join': ['', ['/aws/lambda/', {'Ref': 'LambdaFunction'}]]}}} (existing: {'Environment', 'LambdaFunctionRole', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 2
DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 3 unresolved dependencies in loop iteration 2
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunction: None
DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "Lambda::Function" in region us-east-1: create_function {'FunctionName': 'forward-sns-messages-to-slack', 'Runtime': 'python3.7', 'Role': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'Handler': 'index.handler', 'Code': {'ZipFile': b'PK\x03\x04\x14\x00\x00\x00\x00\x00\xc8f\x89QuQ\x92\x1bo\x00\x00\x00o\x00\x00\x00\x08\x00\x00\x00index.pyimport json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\nPK\x01\x02\x14\x03\x14\x00\x00\x00\x00\x00\xc8f\x89QuQ\x92\x1bo\x00\x00\x00o\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00index.pyPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x006\x00\x00\x00\x95\x00\x00\x00\x00\x00'}, 'Environment': {'Variables': {'AWS_ACCOUNT': 'ci'}}, 'Timeout': 20}
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: None
DEBUG:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunction need not be deployed (is_updateable=True): {'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'forward-sns-messages-to-slack', 'Role': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'Runtime': 'python3.7', 'Handler': 'index.handler', 'Code': {'ZipFile': 'import json\ndef handler(event, context):\n  return json.dumps({"message_code": 200, "message_info": "success"})\n'}, 'Timeout': 20, 'Environment': {'Variables': {'AWS_ACCOUNT': 'ci'}}, 'Configuration': {'FunctionName': 'forward-sns-messages-to-slack', 'FunctionArn': 'arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack', 'Runtime': 'python3.7', 'Role': 'arn:aws:iam::000000000000:role/cf-slack-sns-topic-LambdaFunctionRole', 'Handler': 'index.handler', 'CodeSize': 225, 'Description': '', 'Timeout': 20, 'LastModified': '2020-12-09T02:54:16.084+0000', 'CodeSha256': '9tfTkusinpzk8WaQb0p1tYygjXUyJQ6jzopi2t31WKc=', 'Version': '$LATEST', 'VpcConfig': {}, 'Environment': {'Variables': {'AWS_ACCOUNT': 'ci'}}, 'TracingConfig': {'Mode': 'PassThrough'}, 'RevisionId': 'b25a07c8-6926-4585-9337-8d41da3d08f1', 'State': 'Active', 'LastUpdateStatus': 'Successful', 'PackageType': 'Zip'}, 'Tags': {}}} True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/SnsTopic: True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
DEBUG:localstack.utils.cloudformation.template_deployer: Dependency for resource PermissionForSnsToInvokeLambda not yet deployed: SnsTopic {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Protocol': 'lambda'}]}}
INFO:localstack.services.cloudformation.cloudformation_starter: Resource PermissionForSnsToInvokeLambda cannot be deployed, found unsatisfied dependencies. ['SnsTopic'] - {'Type': 'AWS::Lambda::Permission', 'Properties': {'FunctionName': {'Fn::GetAtt': ['LambdaFunction', 'Arn']}, 'Action': 'lambda:InvokeFunction', 'Principal': 'sns.amazonaws.com', 'SourceArn': {'Ref': 'SnsTopic'}}} (existing: {'LambdaFunction', 'Environment', 'LambdaFunctionRole', 'AWS::StackName', 'AWS::Region', 'AWS::AccountId', 'AWS::StackId', 'AWS::URLSuffix', 'AWS::Partition'})
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/LambdaFunctionLogGroup: None
DEBUG:localstack.services.cloudformation.cloudformation_starter: Deploying CloudFormation resource (update=False, exists=False, updateable=False): {'Type': 'AWS::SNS::Topic', 'Properties': {'TopicName': 'slack-sns-topic', 'Subscription': [{'Endpoint': 'arn:aws:lambda:us-east-1:000000000000:function:forward-sns-messages-to-slack', 'Protocol': 'lambda'}]}}
DEBUG:localstack.utils.cloudformation.template_deployer: Running action "create" for resource type "SNS::Topic" id "SnsTopic"
DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "SNS::Topic" in region us-east-1: create_topic {'Name': 'slack-sns-topic'}
DEBUG:localstack.utils.cloudformation.template_deployer: Extract resource attribute: Lambda::Function PhysicalResourceId
DEBUG:localstack.services.cloudformation.cloudformation_starter: Resource LambdaFunctionLogGroup need not be deployed (is_updateable=False): {'Type': 'AWS::Logs::LogGroup', 'DependsOn': 'LambdaFunction', 'Properties': {'RetentionInDays': 7, 'LogGroupName': '/aws/lambda/forward-sns-messages-to-slack', 'logGroupName': '/aws/lambda/forward-sns-messages-to-slack', 'creationTime': 1607482455942, 'metricFilterCount': 0, 'arn': 'arn:aws:logs:us-east-1:000000000000:log-group:/aws/lambda/forward-sns-messages-to-slack', 'storedBytes': 0}} True
DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 3
DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 1 unresolved dependencies in loop iteration 3
DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently processing (update=False) resource slack-sns-topic/PermissionForSnsToInvokeLambda: None
WARNING:moto: No Moto CloudFormation support for AWS::Lambda::Permission
DEBUG:localstack.services.cloudformation.cloudformation_starter: Running CloudFormation stack deployment loop iteration 4
DEBUG:localstack.services.cloudformation.cloudformation_starter: Found 0 unresolved dependencies in loop iteration 4
```

# Steps to reproduce
1. Deploy the template below to CloudFormation on localstack.
```yaml
---
AWSTemplateFormatVersion: "2010-09-09"

Resources:
  SnsTopic:
    Type: AWS::SNS::Topic
    Properties: 
      TopicName: slack-sns-topic
      Subscription: 
        - Endpoint: !GetAtt LambdaFunction.Arn
          Protocol: lambda
  PermissionForSnsToInvokeLambda: 
    Type: AWS::Lambda::Permission
    Properties: 
      FunctionName: !GetAtt LambdaFunction.Arn
      Action: "lambda:InvokeFunction"
      Principal: "sns.amazonaws.com"
      SourceArn: !Ref SnsTopic
  LambdaFunctionLogGroup:
    Type: AWS::Logs::LogGroup
    DependsOn: LambdaFunction
    Properties: 
      RetentionInDays: 7
      LogGroupName: !Join ["", ["/aws/lambda/", !Ref LambdaFunction]]
  LambdaFunctionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
          Action:
          - sts:AssumeRole
      Path: /
      Policies:
      - PolicyName: slack-sns-topic
        PolicyDocument:
          Statement:
          - Effect: Allow
            Action:
            - 'logs:*'
            Resource: 'arn:aws:logs:*:*:*'
  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: "forward-sns-messages-to-slack"
      Role: !GetAtt LambdaFunctionRole.Arn
      Runtime: "python3.7"
      Handler: index.handler
      Code: 
        ZipFile: |
          import json
          def handler(event, context):
            return json.dumps({"message_code": 200, "message_info": "success"})
      Timeout: 20
```

resource_id = canonical_json(json_safe(props))
                resource_id = md5(resource_id)
            props[entry[1]] = 'cf-%s-%s' % (stack_name, resource_id)
def apply_patches():
    """ Apply patches to make LocalStack seamlessly interact with the moto backend.
        TODO: Eventually, these patches should be contributed to the upstream repo! """
    
    parsing.MODEL_MAP.update(MODEL_MAP)
    
    parsing.ACCOUNT_ID = TEST_AWS_ACCOUNT_ID
    
    def clean_json(resource_json, resources_map):
        try:
            rs = clean_json_orig(resource_json, resources_map)
        except RecursionError:
            if isinstance(resource_json, dict) and 'Ref' in resource_json:
                LOG.info('Potential circular dependency detected when resolving Ref "%s"' % resource_json['Ref'])
                return resource_json['Ref']
            raise
        if isinstance(resource_json, dict):
            attr_ref = resource_json.get('Fn::GetAtt')
            if isinstance(attr_ref, list) and rs == resource_json:
                
                
                
                map_keys = list(resources_map.keys())
                LOG.debug('Unable to resolve attribute reference %s in resource map keys %s' % (attr_ref, map_keys))
                if attr_ref[0] in map_keys and not resources_map[attr_ref[0]]:
                    raise DependencyNotYetSatisfied(
                        resource_ids=attr_ref[0],