import json


def get_stack_name(tags_file, stack_name_tags):
    """Determines the CloudFormation stack name"""
    with open(tags_file, "r") as f:
        tags = json.load(f)
        selections = {}
        for tag in tags:
            for n in stack_name_tags:
                for varient in (n, n.upper(), n.lower, n.title()):
                    if tag['Key'] == varient:
                        selections[n] = tag['Value']
    for t in stack_name_tags:
        if t not in selections:
            raise KeyError(
                'There is no "{0}" tag in {1}'.format(t, tags_file))

    return '-'.join((selections[t] for t in stack_name_tags))