# Buggy code
def _convert_sam_function_resource(name, resource_properties, layers):
    """
    Converts a AWS::Serverless::Function resource to a Function configuration usable by the provider.

    :param string name: LogicalID of the resource NOTE: This is *not* the function name because not all functions
        declare a name
    :param dict resource_properties: Properties of this resource
    :return samcli.commands.local.lib.provider.Function: Function configuration
    """

    codeuri = SamFunctionProvider._extract_sam_function_codeuri(
        name, resource_properties, "CodeUri"
    )

    LOG.debug(
        "Found Serverless function with name='%s' and CodeUri='%s'", name, codeuri
    )

    return Function(
        name=name,
        runtime=resource_properties.get("Runtime"),
        memory=resource_properties.get("MemorySize"),
        timeout=resource_properties.get("Timeout"),
        handler=resource_properties.get("Handler"),
        codeuri=codeuri,
        environment=resource_properties.get("Environment"),
        rolearn=resource_properties.get("Role"),
        layers=layers,
    )


# Traceback (TypeError)
2019-01-11 00:29:55 Found one Lambda function with name 'provisionAppSlaves'
2019-01-11 00:29:55 Found one Lambda function with name 'provisionSeleniumStandalones'
2019-01-11 00:29:55 Invoking index.provisionAppSlaves (nodejs8.10)
2019-01-11 00:29:55 Invoking index.provisionSeleniumStandalones (nodejs8.10)
2019-01-11 00:29:55 Environment variables overrides data is standard format
2019-01-11 00:29:55 Environment variables overrides data is standard format
2019-01-11 00:29:55 Loading AWS credentials from session with profile 'None'
2019-01-11 00:29:55 Loading AWS credentials from session with profile 'None'
2019-01-11 00:29:55 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-01-11 00:29:55 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-01-11 00:29:55 Changing event name from before-call.apigateway to before-call.api-gateway
2019-01-11 00:29:55 Changing event name from before-call.apigateway to before-call.api-gateway
2019-01-11 00:29:55 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-01-11 00:29:55 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-01-11 00:29:55 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-01-11 00:29:55 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-01-11 00:29:55 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-01-11 00:29:55 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-01-11 00:29:55 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-01-11 00:29:55 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-01-11 00:29:55 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-01-11 00:29:55 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-01-11 00:29:55 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-01-11 00:29:55 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-01-11 00:29:55 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-01-11 00:29:55 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-01-11 00:29:55 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-01-11 00:29:55 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-01-11 00:29:55 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-01-11 00:29:55 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-01-11 00:29:55 Looking for credentials via: env
2019-01-11 00:29:55 Looking for credentials via: assume-role
2019-01-11 00:29:55 Looking for credentials via: shared-credentials-file
2019-01-11 00:29:55 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-11 00:29:55 Resolving code path. Cwd=/Source/purpleteam-lambda, CodeUri=./selenium-standalone-provisioner
2019-01-11 00:29:55 Resolved absolute path to code is /Source/purpleteam-lambda/selenium-standalone-provisioner
2019-01-11 00:29:55 Code /Source/purpleteam-lambda/selenium-standalone-provisioner is not a zip/jar file
2019-01-11 00:29:55 Trying paths: ['.docker/config.json', '.dockercfg']
2019-01-11 00:29:55 No config file found
2019-01-11 00:29:55 Trying paths: ['.docker/config.json', '.dockercfg']
2019-01-11 00:29:55 No config file found
2019-01-11 00:29:55 http://localhost:None "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None
2019-01-11 00:29:55 Looking for auth config
2019-01-11 00:29:55 No auth config in memory - loading from filesystem
2019-01-11 00:29:55 Trying paths: ['.docker/config.json', '.dockercfg']
2019-01-11 00:29:55 No config file found
2019-01-11 00:29:55 Looking for auth entry for 'docker.io'
2019-01-11 00:29:55 No entry found
2019-01-11 00:29:55 No auth config found
2019-01-11 00:29:55 Looking for credentials via: env
2019-01-11 00:29:55 Looking for credentials via: assume-role
2019-01-11 00:29:55 Looking for credentials via: shared-credentials-file
2019-01-11 00:29:55 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-11 00:29:55 Resolving code path. Cwd=/Source/purpleteam-lambda, CodeUri=./app-slave-provisioner
2019-01-11 00:29:55 Resolved absolute path to code is /Source/purpleteam-lambda/app-slave-provisioner
2019-01-11 00:29:55 Code /Source/purpleteam-lambda/app-slave-provisioner is not a zip/jar file
2019-01-11 00:29:55 Trying paths: ['.docker/config.json', '.dockercfg']
2019-01-11 00:29:55 No config file found
2019-01-11 00:29:55 Trying paths: ['.docker/config.json', '.dockercfg']
2019-01-11 00:29:55 No config file found
2019-01-11 00:29:55 http://localhost:None "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None
2019-01-11 00:29:55 Looking for auth config
2019-01-11 00:29:55 No auth config in memory - loading from filesystem
2019-01-11 00:29:55 Trying paths: ['.docker/config.json', '.dockercfg']
2019-01-11 00:29:55 No config file found
2019-01-11 00:29:55 Looking for auth entry for 'docker.io'
2019-01-11 00:29:55 No entry found
2019-01-11 00:29:55 No auth config found
2019-01-11 00:29:58 http://localhost:None "POST /v1.35/images/create?tag=nodejs8.10&amp;fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-01-11 00:29:58 Mounting /Source/purpleteam-lambda/selenium-standalone-provisioner as /var/task:ro inside runtime container
2019-01-11 00:29:58 http://localhost:None "POST /v1.35/images/create?tag=nodejs8.10&amp;fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-01-11 00:29:58 Mounting /Source/purpleteam-lambda/app-slave-provisioner as /var/task:ro inside runtime container
2019-01-11 00:29:58 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 201
2019-01-11 00:29:58 http://localhost:None "GET /v1.35/containers/156c0040698b3e7be8d314baf595b8f3882711184e9dfb900a05e72662c5990d/json HTTP/1.1" 200 None
2019-01-11 00:29:58 http://localhost:None "GET /v1.35/networks/compose_pt-net HTTP/1.1" 200 None
2019-01-11 00:29:58 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 201
2019-01-11 00:29:58 http://localhost:None "GET /v1.35/containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9/json HTTP/1.1" 200 None
2019-01-11 00:29:58 http://localhost:None "GET /v1.35/networks/compose_pt-net HTTP/1.1" 200 None
2019-01-11 00:29:58 http://localhost:None "POST /v1.35/networks/a4f1162d57b3f5aff37729656ef2a506c27a264cd7665ec0703a4ea9334f988c/connect HTTP/1.1" 200 0
2019-01-11 00:29:58 http://localhost:None "GET /v1.35/containers/156c0040698b3e7be8d314baf595b8f3882711184e9dfb900a05e72662c5990d/json HTTP/1.1" 200 None
2019-01-11 00:29:58 http://localhost:None "POST /v1.35/networks/a4f1162d57b3f5aff37729656ef2a506c27a264cd7665ec0703a4ea9334f988c/connect HTTP/1.1" 200 0
2019-01-11 00:29:58 http://localhost:None "GET /v1.35/containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9/json HTTP/1.1" 200 None
2019-01-11 00:29:59 http://localhost:None "POST /v1.35/containers/156c0040698b3e7be8d314baf595b8f3882711184e9dfb900a05e72662c5990d/start HTTP/1.1" 204 0
2019-01-11 00:29:59 Starting a timer for 3 seconds for function 'provisionSeleniumStandalones'
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 1071, in run
self.finished.wait(self.interval)
File "/usr/lib/python2.7/threading.py", line 614, in wait
self.__cond.wait(timeout)
File "/usr/lib/python2.7/threading.py", line 349, in wait
endtime = _time() + timeout
TypeError: unsupported operand type(s) for +: 'float' and 'str'

2019-01-11 00:29:59 http://localhost:None "GET /v1.35/containers/156c0040698b3e7be8d314baf595b8f3882711184e9dfb900a05e72662c5990d/json HTTP/1.1" 200 None
2019-01-11 00:29:59 http://localhost:None "POST /containers/156c0040698b3e7be8d314baf595b8f3882711184e9dfb900a05e72662c5990d/attach?stream=1&amp;stdin=0&amp;logs=1&amp;stderr=1&amp;stdout=1 HTTP/1.1" 101 0
START RequestId: 4de742e6-2284-13c9-520f-fb2996acc87e Version: $LATEST
2019-01-11 00:29:59 http://localhost:None "POST /v1.35/containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9/start HTTP/1.1" 204 0
2019-01-11 00:29:59 Starting a timer for 3 seconds for function 'provisionAppSlaves'
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 1071, in run
self.finished.wait(self.interval)
File "/usr/lib/python2.7/threading.py", line 614, in wait
self.__cond.wait(timeout)
File "/usr/lib/python2.7/threading.py", line 349, in wait
endtime = _time() + timeout
TypeError: unsupported operand type(s) for +: 'float' and 'str'

2019-01-11 00:29:59 http://localhost:None "GET /v1.35/containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9/json HTTP/1.1" 200 None
2019-01-11 00:29:59 http://localhost:None "POST /containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9/attach?stream=1&amp;stdin=0&amp;logs=1&amp;stderr=1&amp;stdout=1 HTTP/1.1" 101 0
START RequestId: c591f426-93b2-1683-1de2-db6671d97edc Version: $LATEST
END RequestId: c591f426-93b2-1683-1de2-db6671d97edc
REPORT RequestId: c591f426-93b2-1683-1de2-db6671d97edc	Duration: 85.55 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 39 MB
2019-01-11 00:30:00 http://localhost:None "GET /v1.35/containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9/json HTTP/1.1" 200 None
2019-01-11 00:30:00 http://localhost:None "DELETE /v1.35/containers/7aa23728a90bcd90a5155579521635a953205a1345f57a00bab825c6fd1ff0a9?force=True&amp;link=False&amp;v=False HTTP/1.1" 204 0

# Fixed code
def _convert_sam_function_resource(name, resource_properties, layers):
    """
    Converts a AWS::Serverless::Function resource to a Function configuration usable by the provider.

    :param string name: LogicalID of the resource NOTE: This is *not* the function name because not all functions
        declare a name
    :param dict resource_properties: Properties of this resource
    :return samcli.commands.local.lib.provider.Function: Function configuration
    """

    codeuri = SamFunctionProvider._extract_sam_function_codeuri(
        name, resource_properties, "CodeUri"
    )

    LOG.debug(
        "Found Serverless function with name='%s' and CodeUri='%s'", name, codeuri
    )

    timeout = resource_properties.get("Timeout")
    if isinstance(timeout, str):
        try:
            timeout = ast.literal_eval(timeout)
        except ValueError:
            raise InvalidSamTemplateException(
                "Invalid Number for Timeout: {}".format(timeout)
            )

    return Function(
        name=name,
        runtime=resource_properties.get("Runtime"),
        memory=resource_properties.get("MemorySize"),
        timeout=timeout,
        handler=resource_properties.get("Handler"),
        codeuri=codeuri,
        environment=resource_properties.get("Environment"),
        rolearn=resource_properties.get("Role"),
        layers=layers,
    )