def get_functions(template):
    """
    Extracts functions and environment variables from a template

    This returns a dict with the function name as the key and a list of variable names
    as value.
    """

    # Extract variables from the Globals section
    try:
        global_variables = list(template["Globals"]["Function"]["Environment"]["Variables"].keys())
    except KeyError:
        global_variables = []

    # Extract functions in the Resources section
    functions = {}

    for name, resource in template.get("Resources", {}).items():
        if resource.get("Type", "") != "AWS::Serverless::Function":
            continue

        try:
            local_variables = list(resource["Properties"]["Environment"]["Variables"].keys())
        except KeyError:
            local_variables = []

        # Don't add functions without environment variables
        if local_variables or global_variables:
            functions[name] = global_variables + local_variables

    return functions