# Buggy code
def get_bucket(self, bucket_name, *args, **kwargs):
    bucket_name = s3_listener.normalize_bucket_name(bucket_name)
    return get_bucket_orig(bucket_name, *args, **kwargs)


# Traceback (KeyError)
localstack_main | 2020-03-17T14:10:42:warning:moto: No Moto CloudFormation support for AWS::S3::BucketPolicy
localstack_main | 2020-03-17T14:10:47:warning:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:sample1-local-downloadFile
localstack_main | 2020-03-17T14:10:47:warning:localstack.services.cloudformation.cloudformation_starter: Unable to extract id for resource IamRoleLambdaExecution: {'Role': {'Path': '/', 'RoleName': 'sample1-local-us-east-1-lambdaRole', 'RoleId': '4uzole7bkp69kfgntgrq', 'Arn': 'arn:aws:iam::000000000000:role/sample1-local-us-east-1-lambdaRole', 'CreateDate': datetime.datetime(2020, 3, 17, 14, 10, 47, 927000, tzinfo=tzlocal()), 'AssumeRolePolicyDocument': {'Version': '2012-10-17', 'Statement': [{'Effect': 'Allow', 'Principal': {'Service': ['lambda.amazonaws.com']}, 'Action': ['sts:AssumeRole']}]}, 'MaxSessionDuration': 3600}, 'ResponseMetadata': {'RequestId': '4a93ceee-9966-11e1-b624-b1aEXAMPLE7c', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'BaseHTTP/0.6 Python/3.8.2', 'date': 'Tue, 17 Mar 2020 14:10:47 GMT', 'content-type': 'text/html; charset=utf-8', 'content-length': '709', 'access-control-allow-origin': '*', 'access-control-allow-methods': 'HEAD,GET,PUT,POST,DELETE,OPTIONS,PATCH', 'access-control-allow-headers': 'authorization,content-type,content-md5,cache-control,x-amz-content-sha256,x-amz-date,x-amz-security-token,x-amz-user-agent,x-amz-target,x-amz-acl,x-amz-version-id,x-localstack-target,x-amz-tagging', 'access-control-expose-headers': 'x-amz-version-id'}, 'RetryAttempts': 0}}
localstack_main | 2020-03-17T14:10:47:warning:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:us-east-1:000000000000:function:sample1-local-downloadFile
localstack_main | 2020-03-17T14:10:48:ERROR:localstack.services.cloudformation.cloudformation_starter: Unable to parse and create resource "DownloadFileLambdaFunction": An error occurred (InvalidParameterValueException) when calling the None operation: Error occurred while GetObject. S3 Error Code: NoSuchBucket. S3 Error Message: The specified bucket does not exist Traceback (most recent call last):
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/models.py", line 1190, in get_bucket
localstack_main |     return self.buckets[bucket_name]
localstack_main | KeyError: '__local__'
localstack_main |
localstack_main | During handling of the above exception, another exception occurred:
localstack_main |
localstack_main | Traceback (most recent call last):
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/awslambda/models.py", line 219, in __init__
localstack_main |     key = s3_backend.get_key(self.code["S3Bucket"], self.code["S3Key"])
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/models.py", line 1323, in get_key
localstack_main |     bucket = self.get_bucket(bucket_name)
localstack_main |   File "/opt/code/localstack/localstack/services/s3/s3_starter.py", line 103, in get_bucket
localstack_main |     return get_bucket_orig(bucket_name, *args, **kwargs)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/models.py", line 1192, in get_bucket
localstack_main |     raise MissingBucket(bucket=bucket_name)
localstack_main | moto.s3.exceptions.MissingBucket: 404 Not Found: <?xml version="1.0" encoding="UTF-8"?>
localstack_main | <Error>
localstack_main |     <Code>NoSuchBucket</Code>
localstack_main |     <Message>The specified bucket does not exist</Message>
localstack_main |     <BucketName>__local__</BucketName>
localstack_main |     <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
localstack_main | </Error>
localstack_main |
localstack_main | During handling of the above exception, another exception occurred:
localstack_main |
localstack_main | Traceback (most recent call last):
localstack_main |   File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 174, in parse_and_create_resource
localstack_main |     return _parse_and_create_resource(logical_id, resource_json,
localstack_main |   File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 242, in _parse_and_create_resource
localstack_main |     raise moto_create_error
localstack_main |   File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 228, in _parse_and_create_resource
localstack_main |     resource = parse_and_create_resource_orig(logical_id,
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/cloudformation/parsing.py", line 338, in parse_and_create_resource
localstack_main |     resource = resource_class.create_from_cloudformation_json(
localstack_main |   File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 549, in Lambda_create_from_cloudformation_json
localstack_main |     return Lambda_create_from_cloudformation_json_orig(resource_name, cloudformation_json, region_name)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/awslambda/models.py", line 516, in create_from_cloudformation_json
localstack_main |     fn = backend.create_function(spec)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/awslambda/models.py", line 822, in create_function
localstack_main |     fn = LambdaFunction(spec, self.region_name, version="$LATEST")
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/awslambda/models.py", line 222, in __init__
localstack_main |     raise InvalidParameterValueException(
localstack_main | moto.awslambda.exceptions.InvalidParameterValueException: An error occurred (InvalidParameterValueException) when calling the None operation: Error occurred while GetObject. S3 Error Code: NoSuchBucket. S3 Error Message: The specified bucket does not exist

# Fixed code
def get_bucket(self, bucket_name, *args, **kwargs):
    bucket_name = s3_listener.normalize_bucket_name(bucket_name)
    if bucket_name == BUCKET_MARKER_LOCAL:
        return None
    return get_bucket_orig(bucket_name, *args, **kwargs)